Skip to content

Commit 41626d6

Browse files
committed
HardwireGen: Fix properties
1 parent 5a249c0 commit 41626d6

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

src/WattleScript.HardwireGen.Test/SanityTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,17 @@ public void CallMethodOnExtra()
4343
sc.Globals["data"] = new GenericExtra<string>() { Value = "Hello" };
4444
Assert.AreEqual(1234, sc.DoString("return data.DoThing()").CastToInt());
4545
}
46+
47+
[Test]
48+
public void Property()
49+
{
50+
var sc = new Script(CoreModules.None);
51+
var p = new WithProperty();
52+
sc.Globals["data"] = p;
53+
Assert.AreEqual(6, sc.DoString(@"
54+
data.Property = 3
55+
return data.Property + 3
56+
").CastToInt());
57+
Assert.AreEqual(3, p.Property);
58+
}
4659
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using WattleScript.Interpreter;
2+
3+
namespace WattleScript.HardwireGen.Test;
4+
5+
[WattleScriptUserData]
6+
public class WithProperty
7+
{
8+
public int Property { get; set; }
9+
}

src/WattleScript.HardwireGen/HardwireInterop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static void GenerateMethod(TabbedWriter tw, string typeName, HardwireMethod m)
115115
if (!m.Constructor)
116116
{
117117
tw.Append("self.");
118-
tw.Append(m.Name);
118+
tw.Append(m.PropertyName?? m.Name);
119119
}
120120
else
121121
{

src/WattleScript.HardwireGen/HardwireModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public record struct TypeOrDiagnostic(HardwireType? Type, CachedDiagnostic? Diag
1515
public record struct HardwireField(string ClassName, string Name, string Type, bool Read, bool Write);
1616
public record struct HardwireParameter(string Name, string Type, bool IsParams);
1717
public record struct HardwireOverload(string ClassName, bool ReturnsVoid, EquatableArray<HardwireParameter> Parameters);
18-
public record struct HardwireMethod(string Name, bool Property, bool Constructor, EquatableArray<HardwireOverload> Overloads);
18+
public record struct HardwireMethod(string Name, string? PropertyName, bool Property, bool Constructor, EquatableArray<HardwireOverload> Overloads);
1919

2020
public record struct CachedDiagnostic(int DiagnosticIndex, string Target, string? Target2, CachedLocation? Location);
2121

src/WattleScript.HardwireGen/HardwireSourceGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static HardwireType FromTypeSymbol(INamedTypeSymbol symbol)
255255
overloads.Add(new HardwireOverload(clsName, o.ReturnsVoid, new(parameters.ToArray())));
256256
}
257257

258-
hardwireMethods.Add(new(m.PropertyName ?? m.Name, m.Property, m.Constructor, new(overloads.ToArray())));
258+
hardwireMethods.Add(new(m.Name, m.PropertyName, m.Property, m.Constructor, new(overloads.ToArray())));
259259
}
260260

261261
foreach (var f in fields.Values)

0 commit comments

Comments
 (0)