Analyzer adds a "this" pointer to methods
This commit is contained in:
parent
ffe873a3e4
commit
342e9a3a89
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user