Skip to content

Commit

Permalink
Fix class cast exception with ObjectSource
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SquidDev committed Jul 7, 2023
1 parent d351bc3 commit 9ea7f45
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public boolean forEachMethod(Object object, TargetedConsumer<T> consumer) {
for (var extra : source.getExtra()) {
var extraMethods = getMethods(extra.getClass());
if (!extraMethods.isEmpty()) hasMethods = true;
for (var method : extraMethods) consumer.accept(object, method.name(), method.method(), method);
for (var method : extraMethods) consumer.accept(extra, method.name(), method.method(), method);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testDynamicPeripheral() {

@Test
public void testExtra() {
ComputerBootstrap.run("assert(extra.go, 'go')\nassert(extra.go2, 'go2')",
ComputerBootstrap.run("assert(extra.go() == nil, 'go')\nassert(extra.go2() == 456, 'go2')",
x -> x.addApi(new ExtraObject()),
50);
}
Expand Down Expand Up @@ -163,7 +163,8 @@ public String[] getNames() {
}

@LuaFunction
public final void go2() {
public final int go2() {
return 456;
}

@Override
Expand Down

0 comments on commit 9ea7f45

Please sign in to comment.