diff --git a/.release-notes/4167.md b/.release-notes/4167.md new file mode 100644 index 0000000000..a95170d32c --- /dev/null +++ b/.release-notes/4167.md @@ -0,0 +1,22 @@ +## Fix compiler crash related to using private types as default arguments + +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. diff --git a/src/libponyc/verify/call.c b/src/libponyc/verify/call.c index 814d60e25d..c820819f9d 100644 --- a/src/libponyc/verify/call.c +++ b/src/libponyc/verify/call.c @@ -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); diff --git a/test/libponyc-run/private-type-as-default-argument-in-public-function/lib/lib.pony b/test/libponyc-run/private-type-as-default-argument-in-public-function/lib/lib.pony new file mode 100644 index 0000000000..4bcad15e24 --- /dev/null +++ b/test/libponyc-run/private-type-as-default-argument-in-public-function/lib/lib.pony @@ -0,0 +1,4 @@ +primitive _Private + +primitive Public + fun apply[T](v: (T | _Private) = _Private): None => None diff --git a/test/libponyc-run/private-type-as-default-argument-in-public-function/main.pony b/test/libponyc-run/private-type-as-default-argument-in-public-function/main.pony new file mode 100644 index 0000000000..41c4a74d2e --- /dev/null +++ b/test/libponyc-run/private-type-as-default-argument-in-public-function/main.pony @@ -0,0 +1,5 @@ +use lib = "lib" + +actor Main + new create(env: Env) => + lib.Public.apply[U8]()