Skip to content

Commit e75058e

Browse files
committed
Start fixing field instances
1 parent 8987ae9 commit e75058e

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ public TypeID getType() {
152152
return type;
153153
}
154154

155+
@Override
156+
public void setType(TypeID type) {
157+
super.setType(type);
158+
159+
if (autoGetter != null)
160+
this.autoGetter.setType(type);
161+
if (autoSetter != null)
162+
this.autoSetter.setType(type);
163+
}
164+
155165
@Override
156166
public Modifiers getModifiers() {
157167
return modifiers;

CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ public void setBody(Statement body) {
3131
this.body = body;
3232

3333
if (type == BasicTypeID.UNDETERMINED) {
34-
body.getReturnType().ifPresent(returnType -> {
35-
this.type = returnType;
36-
this.header = new FunctionHeader(type);
37-
});
34+
body.getReturnType().ifPresent(this::setType);
3835
}
3936
}
4037

38+
public void setType(TypeID type) {
39+
if (type == null) {
40+
throw new NullPointerException();
41+
}
42+
this.type = type;
43+
this.header = new FunctionHeader(type);
44+
}
45+
4146
@Override
4247
public String getCanonicalName() {
4348
return definition.getFullName() + ":get:" + name;

CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/PropertyMember.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public PropertyMember(CodePosition position, HighLevelDefinition definition, Mod
1414
if (type == null)
1515
throw new NullPointerException();
1616

17-
this.type = type;
17+
this.setType(type);
1818
}
1919

2020
public TypeID getType() {

CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/SetterMember.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ public void setBody(Statement body) {
3434
this.body = body;
3535
}
3636

37+
public void setType(TypeID type) {
38+
if (type == null) {
39+
throw new NullPointerException();
40+
}
41+
this.type = type;
42+
this.parameter = new FunctionParameter(type, "$");
43+
this.header = new FunctionHeader(BasicTypeID.VOID, this.parameter);
44+
}
45+
3746
@Override
3847
public String getCanonicalName() {
3948
return definition.getFullName() + ":get:" + name;
@@ -67,9 +76,7 @@ public <C, R> R accept(C context, MemberVisitorWithContext<C, R> visitor) {
6776
@Override
6877
public void inferFromOverride(MethodInstance overrides) {
6978
if (type == BasicTypeID.UNDETERMINED) {
70-
this.type = overrides.getHeader().getReturnType();
71-
parameter = new FunctionParameter(overrides.getHeader().getReturnType(), "$");
72-
header = new FunctionHeader(BasicTypeID.VOID, parameter);
79+
setType(overrides.getHeader().getReturnType());
7380
}
7481
}
7582

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#output: Hello World
2+
3+
public class MyClass {
4+
public static var myVariable = "Hello World";
5+
}
6+
7+
println(MyClass.myVariable);

0 commit comments

Comments
 (0)