diff --git a/mypy/fastparse.py b/mypy/fastparse.py index ee14cea02746..4d778ee066fc 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -1799,7 +1799,7 @@ def visit_MatchMapping(self, n: ast3.MatchMapping) -> MappingPattern: if n.rest is None: rest = None else: - rest = NameExpr(n.rest) + rest = self.set_line(NameExpr(n.rest), n) node = MappingPattern(keys, values, rest) return self.set_line(node, n) diff --git a/test-data/unit/check-python310.test b/test-data/unit/check-python310.test index 6a6409f7aee6..26cb20151c00 100644 --- a/test-data/unit/check-python310.test +++ b/test-data/unit/check-python310.test @@ -3194,3 +3194,15 @@ def fun(val: str | None): case types.NoneType(): reveal_type(val) # N: Revealed type is "None" [builtins fixtures/tuple.pyi] + +[case testMatchMappingRestErrorLocation] +rest: list[int] +data: list[int] +match data: + case [1, *rest]: + ... +config: dict[str, object] +match config: + case {"a": 1, **rest}: # E: Incompatible types in capture pattern (pattern captures type "dict[str, object]", variable has type "list[int]") + ... +[builtins fixtures/dict.pyi]