Analyzer adds a "this" pointer to methods

This commit is contained in:
Sasha Koshka 2023-12-02 23:06:58 -05:00
parent ffe873a3e4
commit 342e9a3a89
2 changed files with 26 additions and 0 deletions

View File

@ -50,6 +50,20 @@ func (this *Tree) analyzeMethod (
this.analyzeType(method.Signature.Return, false)
if err != nil { return method, err }
// add owner to method
this.addVariable(&entity.Declaration {
Pos: method.Pos,
Name: "this",
Ty: &entity.TypePointer {
Pos: method.Pos,
Referenced: &entity.TypeNamed {
Pos: method.Pos,
Name: typeName,
Type: owner.Type,
},
},
})
// add incomplete method to complete methods because there is enough
// information for it to be complete from the point of view of other
// parts of the code

View File

@ -41,3 +41,15 @@ Bird: Int
Bird.[main x:Int y:U8 z:Int] = { }
`)
}
func TestMethodThis (test *testing.T) {
testString (test,
`
Number: Int
Number.[add x:Number]:Number = [++[.this] x]
StringHolder: (string:String)
StringHolder.[setString string:String] = {
this.string = string
}
`)
}