(self, o: ValuePattern)
| 202 | return PatternType(union_type, current_type, captures) |
| 203 | |
| 204 | def visit_value_pattern(self, o: ValuePattern) -> PatternType: |
| 205 | current_type = self.type_context[-1] |
| 206 | typ = self.chk.expr_checker.accept(o.expr) |
| 207 | typ = coerce_to_literal(typ) |
| 208 | node = TempNode(current_type) |
| 209 | # Value patterns are essentially a syntactic sugar on top of `if x == Value`. |
| 210 | # They should be treated equivalently. |
| 211 | ok_map, rest_map = self.chk.narrow_type_by_identity_equality( |
| 212 | "==", [node, TempNode(typ)], [current_type, typ], [0, 1], {0} |
| 213 | ) |
| 214 | ok_type = ok_map.get(node, current_type) if ok_map is not None else UninhabitedType() |
| 215 | rest_type = rest_map.get(node, current_type) if rest_map is not None else UninhabitedType() |
| 216 | return PatternType(ok_type, rest_type, {}) |
| 217 | |
| 218 | def visit_singleton_pattern(self, o: SingletonPattern) -> PatternType: |
| 219 | current_type = self.type_context[-1] |
nothing calls this directly
no test coverage detected