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]) +}