Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/WattleScript.Interpreter/Tree/GeneratedClosure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void ResolveScope(ScriptLoadingContext lcontext, Action<ScriptLoadingCont
referenced[s] = new SymbolRefExpression(lcontext, lcontext.Scope.DefineLocal(s));
}
extra?.Invoke(lcontext);
foreach(var e in toResolve) e.ResolveScope(lcontext);
foreach(var e in toResolve) e?.ResolveScope(lcontext);
frame = lcontext.Scope.PopFunction();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public ClassDefinitionStatement(ScriptLoadingContext lcontext) : base(lcontext)
{
var T = lcontext.Lexer.Current;
lcontext.Lexer.Next();
bool resetModifiers = true;
switch (lcontext.Lexer.Current.Type)
{
case TokenType.Brk_Open_Round:
Expand Down Expand Up @@ -180,14 +181,22 @@ public ClassDefinitionStatement(ScriptLoadingContext lcontext) : base(lcontext)
var exp = Expression.Expr(lcontext, true);
fields.Add(T, exp, modifierFlags, false);
break;
case TokenType.Comma: //no-op
case TokenType.Comma:
fields.Add(T, null, modifierFlags, false);
resetModifiers = false;
break;
case TokenType.SemiColon:
break;
default:
CheckTokenType(lcontext, TokenType.SemiColon); //throws error
fields.Add(T, null, modifierFlags, false);
break;
}
modifierFlags = MemberModifierFlags.None;

if (resetModifiers)
{
modifierFlags = MemberModifierFlags.None;
}

break;
}
default:
Expand Down Expand Up @@ -354,6 +363,11 @@ void CompileInit(FunctionBuilder parent)
bc.Emit_CopyPriv();
foreach (var field in fields.Where(x => !x.Flags.HasFlag(MemberModifierFlags.Static)))
{
if (field.Expr == null)
{
continue;
}

field.Expr.CompilePossibleLiteral(bc);
sym["table"].Compile(bc);
bc.Emit_IndexSet(0, 0, field.Name, false, false, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class C {
private a, b, c
p2

C() {
this.a = 2
this.p2 = 20
}

f2() {
print(this.a)
}
}

c = new C()
print(c.a)
c.f2()
print(c.p2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nil
2
20