wvlet / airframe

Essential Building Blocks for Scala
https://wvlet.org/airframe
Apache License 2.0
631 stars 65 forks source link

Surface - Method type exploration #3440

Open OndrejSpanel opened 6 months ago

OndrejSpanel commented 6 months ago

This an exploratory PR for #3433 and #3429

I would like to know where exactly is the type mismatch happening and if perhaps there is a way to avoid it completely, even at cost of reported method surfaces being not 100% accurate.

OndrejSpanel commented 6 months ago

Logging says:

wvlet.airframe.surface.ClassMethodSurface.apply(1, s000, "compare", wvlet.airframe.surface.Primitive.Int, wvlet.airframe.surface.StaticMethodParameter.apply(method = wvlet.airframe.surface.MethodRef.apply(owner = classOf[wvlet.airframe.surface.i3439.OuterType.InnerType], name = "compare", paramTypes = classOf[Base.this.InnerType], isConstructor = false), index = 0, name = "that", isRequired = false, isSecret = false, surface = s001, defaultValue = scala.None, accessor = scala.None, methodArgAccessor = scala.None).toIndexedSeq, scala.Some.apply[scala.Function2[scala.Any, scala.collection.immutable.Seq[scala.Any], scala.Any]](((x: scala.Any, argsΓéâ: scala.collection.immutable.Seq[scala.Any]) => x.asInstanceOf[wvlet.airframe.surface.i3439.OuterType.InnerType].compare(argsΓéâ.apply(0).asInstanceOf[Base.this.InnerType]))))

Notice last part: x.asInstanceOf[wvlet.airframe.surface.i3439.OuterType.InnerType].compare(argsΓéâ.apply(0).asInstanceOf[Base.this.InnerType]))))

Method compare is called, but the argument is of a wrong type. This seems to be a methodCaller field. It is a pity to get a mismatch here, because the external signature is (Any, Seq[Any]) => Any.

When I disable methodCaller creation by replacing it with '{ Option.empty[(Any, Seq[Any]) => Any] }, I get a compiler exception someplace else:

exception while retyping Base.this of class This # -1 java.lang.AssertionError: assertion failed: missing outer accessor in object i3439

OndrejSpanel commented 6 months ago

I have decided not to explore this any more. For my purposes I do not need the objectFactory or methodCaller functionality, therefore I decided to create a fork of the library instead without this functionality. The fork has no other ambition than to serve as a temporary workaround until the issues are fixed here.

If anyone is interested, the fork can be found at https://github.com/OpenGrabeso/light-surface. I intend to publish the artifacts in GitHub Packages.