Parser properly unions position of named types

This commit is contained in:
Sasha Koshka 2024-02-15 01:07:25 -05:00
parent 6b9cdcc239
commit 159317965d
1 changed files with 5 additions and 4 deletions

View File

@ -17,6 +17,7 @@ var startTokensType = []lexer.TokenKind {
func (this *treeParser) parseType () (entity.Type, error) {
err := this.ExpectDesc(descriptionType, startTokensType...)
if err != nil { return nil, err }
pos := this.Pos()
switch this.Kind() {
case lexer.Ident:
@ -25,7 +26,7 @@ func (this *treeParser) parseType () (entity.Type, error) {
if err != nil { return nil, err }
err = this.ExpectNext(lexer.TypeIdent)
if err != nil { return nil, err }
return this.parseTypeNamedCore(ident)
return this.parseTypeNamedCore(pos, ident)
case lexer.TypeIdent:
if this.Value() == "Int" || this.Value() == "UInt" {
@ -46,7 +47,7 @@ func (this *treeParser) parseType () (entity.Type, error) {
}
}
return this.parseTypeNamedCore("")
return this.parseTypeNamedCore(pos, "")
case lexer.Star:
return this.parseTypePointerOrSlice()
@ -69,13 +70,13 @@ func (this *treeParser) parseType () (entity.Type, error) {
panic(this.bug())
}
func (this *treeParser) parseTypeNamedCore (unitNickname string) (entity.Type, error) {
func (this *treeParser) parseTypeNamedCore (pos errors.Position, unitNickname string) (entity.Type, error) {
err := this.Expect(lexer.TypeIdent)
if err != nil { return nil, err }
defer this.Next()
return &entity.TypeNamed {
Position: this.Pos(),
Position: pos.Union(this.Pos()),
Name: this.Value(),
UnitNickname: unitNickname,
}, nil