Skip to content

Commit ddb2800

Browse files
committed
Reject generic args on scalar type annotations
1 parent 37cca5d commit ddb2800

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

vibes/parser.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,10 @@ func (p *parser) parseTypeAtom() *TypeExpr {
11101110
ty.Nullable = nullable
11111111

11121112
if p.peekToken.Type == tokenLT {
1113+
if ty.Kind != TypeArray && ty.Kind != TypeHash {
1114+
p.addParseError(p.curToken.Pos, fmt.Sprintf("type %s does not accept type arguments", ty.Name))
1115+
return nil
1116+
}
11131117
p.nextToken()
11141118
p.nextToken()
11151119
typeArgs := []*TypeExpr{}

vibes/parser_types_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,18 @@ end`
138138
t.Fatalf("expected nullable string type, got %#v", second.Type)
139139
}
140140
}
141+
142+
func TestParserTypeSyntaxRejectsGenericArgsOnScalars(t *testing.T) {
143+
source := `def run(value: int<string>)
144+
value
145+
end`
146+
147+
p := newParser(source)
148+
_, errs := p.ParseProgram()
149+
if len(errs) == 0 {
150+
t.Fatalf("expected parse errors")
151+
}
152+
if got := errs[0].Error(); !strings.Contains(got, "type int does not accept type arguments") {
153+
t.Fatalf("unexpected parse error: %s", got)
154+
}
155+
}

0 commit comments

Comments
 (0)