Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report bespoke error for restricted types parsed as type arguments #2985

Merged
merged 5 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion runtime/parser/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ func defineLessThanOrTypeArgumentsExpression() {
return nil
}()

// `err` is nil means the expression is an invocation
// `err` is nil means the expression is an invocation,
dsainati1 marked this conversation as resolved.
Show resolved Hide resolved
if err == nil {

// The expression was determined to be an invocation.
Expand Down Expand Up @@ -640,6 +640,12 @@ func defineLessThanOrTypeArgumentsExpression() {

} else {

// if the error specifically occurred during parsing restricted types,
// this is still an invocation and we should report that error instead
if strings.Contains(err.Error(), "restricted type") {
dsainati1 marked this conversation as resolved.
Show resolved Hide resolved
return nil, err, true
}

// The previous attempt to parse an invocation failed,
// replay the buffered tokens.

Expand Down
16 changes: 16 additions & 0 deletions runtime/parser/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4474,6 +4474,22 @@ func TestParseLessThanOrTypeArguments(t *testing.T) {
result,
)
})

t.Run("restricted type argument", func(t *testing.T) {

t.Parallel()

_, errs := testParseExpression("foo<X{T}>")
utils.AssertEqualWithDiff(t,
[]error{
&SyntaxError{
Message: "restricted types have been removed; replace with the concrete type or an equivalent intersection type",
Pos: ast.Position{Offset: 6, Line: 1, Column: 6},
},
},
errs,
)
})
}

func TestParseBoolExpression(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions runtime/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func TestParseBuffering(t *testing.T) {

fun isneg(x: SignedFixedPoint): Bool { /* I kinda forget what this is all about */
return x /* but we probably need to figure it out */
< /* ************/((TODO?{/*))************ *//
< /* ************/((TODO?/*))************ *//
dsainati1 marked this conversation as resolved.
Show resolved Hide resolved
-x /* maybe it says NaNs are not negative? */
}
`
Expand All @@ -515,7 +515,7 @@ func TestParseBuffering(t *testing.T) {
[]error{
&SyntaxError{
Message: "expected token identifier",
Pos: ast.Position{Offset: 399, Line: 9, Column: 95},
Pos: ast.Position{Offset: 398, Line: 9, Column: 94},
},
},
err.(Error).Errors,
Expand All @@ -539,8 +539,8 @@ func TestParseBuffering(t *testing.T) {
utils.AssertEqualWithDiff(t,
[]error{
&SyntaxError{
Message: "expected token identifier",
Pos: ast.Position{Offset: 146, Line: 4, Column: 63},
Message: "restricted types have been removed; replace with the concrete type or an equivalent intersection type",
Pos: ast.Position{Offset: 138, Line: 4, Column: 55},
},
},
err.(Error).Errors,
Expand Down
Loading