diff --git a/python/run.n b/python/run.n index 9629a86d..9a77c3e7 100644 --- a/python/run.n +++ b/python/run.n @@ -1 +1,7 @@ -print(["12", "1", "2"][1][1]) \ No newline at end of file +print(match ("Why are you?") { + "Who are you?" -> "I am an example." + "How are you?" -> "I am good." + "Why are you?" -> "Why are *you*?" + "Why are you?" -> "Why are *youu*?" + _ -> "I don't understand." +}) \ No newline at end of file diff --git a/python/scope.py b/python/scope.py index 9960f505..cb3eda96 100644 --- a/python/scope.py +++ b/python/scope.py @@ -1725,6 +1725,23 @@ def type_check_expr(self, expr): first_value_type = self.type_check_expr(first_value) for i, match_value in enumerate(match_block.children): match, value = match_value.children + + if ( + i != len(match_block.children) - 1 + and isinstance(match, lark.Tree) + and len(match.children) == 1 + and isinstance(match.children[0], lark.Token) + and match.children[0].type == "NAME" + and match.children[0].value == "_" + ): + self.errors.append( + TypeCheckError( + match, + "You cannot have more than one default in a match statement" + ) + ) + continue + if ( i != len(match_block.children) - 1 and self.type_check_expr(match) != first_match_type