Skip to content

Commit

Permalink
fix regression introduced in a250336: gracefully handle invalid restr…
Browse files Browse the repository at this point in the history
…ictions
  • Loading branch information
turbolent committed Nov 16, 2021
1 parent ad6895c commit 53ddeff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions runtime/sema/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions runtime/tests/checker/restriction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}

0 comments on commit 53ddeff

Please sign in to comment.