MinecraftForge / ForgeFlower

Forge's modifications to FernFlower. Fixing various bugs/inconsistencies. Main Repo: https://github.com/MinecraftForge/FernFlower
Apache License 2.0
80 stars 44 forks source link

Fix calls to method handle not casting the return value when needed #127

Closed coehlrich closed 1 year ago

coehlrich commented 1 year ago

Fixes not casting return values from polymorphic signature method calls (The methods only exist in MethodHandle and VarHandle currently) to the correct type.

Even though at source level it looks like the methods have a descriptor of ([Ljava/lang/Object;)Ljava/lang/Object or some other return type if the return type is to be kept and the parameter is a varargs parameter, when compiled they get the descriptor of whatever argument types the method call is given and if the method returns an Object a return type of whatever the cast is otherwise the return type is kept.

The specification for this is https://docs.oracle.com/javase/specs/jls/se17/html/jls-15.html#jls-15.12.3.

The diff for 22w45a is https://gist.github.com/coehlrich/4002a2cc38d373aecc467989c96c1231 (There is a call with parameters in DebugMemoryUntracker