From 53ddeffe9d13c0a4ca34e299ae807d5e25d87197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Tue, 16 Nov 2021 15:35:00 -0800 Subject: [PATCH] fix regression introduced in a250336: gracefully handle invalid restrictions --- runtime/sema/checker.go | 4 ++++ runtime/tests/checker/restriction_test.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/runtime/sema/checker.go b/runtime/sema/checker.go index 770021328a..2b80bba90e 100644 --- a/runtime/sema/checker.go +++ b/runtime/sema/checker.go @@ -1141,6 +1141,10 @@ func (checker *Checker) convertRestrictedType(t *ast.RestrictedType) Type { Range: ast.NewRangeFromPositioned(restriction), }) } + + // NOTE: ignore this invalid type + // and do not add it to the restrictions result + continue } restrictions = append(restrictions, restrictionInterfaceType) diff --git a/runtime/tests/checker/restriction_test.go b/runtime/tests/checker/restriction_test.go index 47e30b3867..4e3fa4e273 100644 --- a/runtime/tests/checker/restriction_test.go +++ b/runtime/tests/checker/restriction_test.go @@ -1124,3 +1124,17 @@ func TestCheckRestrictedConformance(t *testing.T) { require.NoError(t, err) } + +func TestCheckInvalidRestriction(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + let x: {h} = nil + `) + + errs := ExpectCheckerErrors(t, err, 2) + + require.IsType(t, &sema.NotDeclaredError{}, errs[0]) + require.IsType(t, &sema.AmbiguousRestrictedTypeError{}, errs[1]) +}