ponyc
ponyc copied to clipboard
Compiler assertion due to not fully reified lambda during reachability analysis
This is a follow up on #3856 which has had a workaround applied in stdlib with #3991
The compiler is asserting due to a type with a TypeParameter that is making it into the list of reachable types. It should have been fully reified by the deferred reification done some frames before the actual failure. That type is a generic lambda ( https://github.com/ponylang/ponyc/blob/786d21c979e19a7ab402e3c270861a64040e03ba/packages/promises/promise.pony#L206 ) that, by assignment fulfills the generic interface: Fulfill[A, B].
The troublesome type causing the assertion in the compiler, as reported in reach.c:210, is: {(A): Promise[B #share] tag}[String val, String val] ref.
Is seems to have the type arguments present, but somehow when the name should be generated, it fails to apply them, or failed to apply them at an earlier place.
A minimal example that exhibits this problem is this:
use "promises"
actor Main
new create(env: Env) =>
let p1 = Promise[String]
// if this type parameter is changed to anything else, the issue does not happen
p1.next[Any tag](recover this~fake_it() end)
let p2 = Promise[String]
p2.flatten_next[String]({(s: String) => Promise[String]})
be fake_it(s: String)
For this example the compiler tries to add the interface method from the Fulfill instance passed to the p1.next call to the lambda
passed as argument to p2.flatten_next. This is the method it tries to add:
promises Fulfill[String val, Any tag]
fun ref apply(value: String val): Any tag => ...
Something is definitely odd here, as this method shouldn't be added to the lambda above, or should it? This one still needs investigation to find the actual root cause leading up to this compiler assertion.