Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for crash when methods with default private type params in remote packages are called #4167

Merged
merged 8 commits into from
Aug 2, 2022
22 changes: 22 additions & 0 deletions .release-notes/4167.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Fix for compiler segfault #4130
stefandd marked this conversation as resolved.
Show resolved Hide resolved

The compiler crash described in #4130 happened with code that attempted to call a method in a different package when this remote method used a package-private type as a default parameter.

```pony
// In the "lib" pacakge

primitive _Private

primitive Public
fun apply[T](v: (T | _Private) = _Private): None => None

// In main
use lib = "lib"

actor Main
new create(env: Env) =>
let p = lib.Public.apply[U8]()
env.out.print(p.string())
```

It was decided that this code is valid Pony code, and this PR fixes the crash so that code like the above compiles.
4 changes: 2 additions & 2 deletions src/libponyc/verify/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ static bool check_partial_function_call(pass_opt_t* opt, ast_t* ast)
ast_id(call_error) == TK_NONE || ast_id(call_error) == TK_DONTCARE);

// Look up the original method definition for this method call.
deferred_reification_t* method_def = lookup(opt, receiver, ast_type(receiver),
ast_name(method));
deferred_reification_t* method_def = lookup_try(opt, receiver, ast_type(receiver),
ast_name(method), true); // allow private types
ast_t* method_ast = method_def->ast;
deferred_reify_free(method_def);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
primitive _Private

primitive Public
fun apply[T](v: (T | _Private) = _Private): None => None
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use lib = "lib"

actor Main
new create(env: Env) =>
let p = lib.Public.apply[U8]()
env.out.print(p.string())
stefandd marked this conversation as resolved.
Show resolved Hide resolved