diff --git a/analyzer/method.go b/analyzer/method.go index 3f4a777..2454e5c 100644 --- a/analyzer/method.go +++ b/analyzer/method.go @@ -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 diff --git a/analyzer/method_test.go b/analyzer/method_test.go index 979594b..f5a0410 100644 --- a/analyzer/method_test.go +++ b/analyzer/method_test.go @@ -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 +} +`) +}