Skip to content

Commit

Permalink
GH-550 Add simple type.panda test and fix call to another constructor…
Browse files Browse the repository at this point in the history
… through 'this' keyword
  • Loading branch information
dzikoysk committed Jan 23, 2021
1 parent 5b9e5b9 commit 13c7a34
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
33 changes: 33 additions & 0 deletions examples/lang/type.panda
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module lang

main {
Foo defaultFoo = new Foo()
log 'Static' == Foo.staticField
log 'Static' == defaultFoo.staticField
log 'Default' == defaultFoo.field
log 'Default' == defaultFoo.field()

Foo foo = new Foo('Custom')
log 'Custom' == foo.field
log 'Custom' == foo.field()
}

open type Foo {

open static String staticField = 'Static'

internal String field

constructor (String field) {
this.field = field
}

constructor () {
this('Default')
}

shared field () -> String {
return field
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.panda_lang.language.architecture.dynamic.AbstractExecutableStatement;
import org.panda_lang.language.architecture.expression.Expression;
import org.panda_lang.language.architecture.expression.ExpressionUtils;
import org.panda_lang.language.architecture.type.member.constructor.ConstructorScope.ConstructorFrame;
import org.panda_lang.language.architecture.type.member.constructor.TypeConstructor;
import org.panda_lang.language.architecture.type.signature.AdjustedMember;
import org.panda_lang.language.interpreter.source.Localizable;
Expand All @@ -44,7 +45,8 @@ public SelfConstructor(Localizable localizable, AdjustedMember<TypeConstructor>

@Override
public @Nullable Object execute(ProcessStack stack, Object instance) throws Exception {
return constructor.invoke(stack, instance, ExpressionUtils.evaluate(stack, instance, arguments));
ConstructorFrame constructorFrame = (ConstructorFrame) instance;
return constructor.invoke(stack, constructorFrame.getInstance(), ExpressionUtils.evaluate(stack, instance, arguments));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.panda_lang.panda.examples.lang

import groovy.transform.CompileStatic
import org.junit.jupiter.api.Test

@CompileStatic
class TypeTest extends LangTestSpecification {

@Test
void 'should handle types' () {
launch 'type.panda'
}

}

0 comments on commit 13c7a34

Please sign in to comment.