Skip to content

Commit 9ea7f45

Browse files
committed
Fix class cast exception with ObjectSource
We were generating methods with the original object, rather than the extra one. Updated our tests to actually catch this. Unfortunately the only places we use this interface is in HTTP responses and transferred files, neither of which show up in the Lua-side tests.
1 parent d351bc3 commit 9ea7f45

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Diff for: projects/core/src/main/java/dan200/computercraft/core/asm/MethodSupplierImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public boolean forEachMethod(Object object, TargetedConsumer<T> consumer) {
7676
for (var extra : source.getExtra()) {
7777
var extraMethods = getMethods(extra.getClass());
7878
if (!extraMethods.isEmpty()) hasMethods = true;
79-
for (var method : extraMethods) consumer.accept(object, method.name(), method.method(), method);
79+
for (var method : extraMethods) consumer.accept(extra, method.name(), method.method(), method);
8080
}
8181
}
8282

Diff for: projects/core/src/test/java/dan200/computercraft/core/asm/MethodTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void testDynamicPeripheral() {
5858

5959
@Test
6060
public void testExtra() {
61-
ComputerBootstrap.run("assert(extra.go, 'go')\nassert(extra.go2, 'go2')",
61+
ComputerBootstrap.run("assert(extra.go() == nil, 'go')\nassert(extra.go2() == 456, 'go2')",
6262
x -> x.addApi(new ExtraObject()),
6363
50);
6464
}
@@ -163,7 +163,8 @@ public String[] getNames() {
163163
}
164164

165165
@LuaFunction
166-
public final void go2() {
166+
public final int go2() {
167+
return 456;
167168
}
168169

169170
@Override

0 commit comments

Comments
 (0)