~sircmpwn/hare#868: 
Function pointers are not assignable to pointers to aliases of functions within tagged unions

type some_func = fn() void;
type t = (*some_func | int);

export fn main() void = {
	func(&empty);
};

fn func(v: t) void = void;
fn empty() void = void;

This currently fails with Argument type *fn() void is not assignable to parameter type t. Works fine if the pointer is moved into the alias, or if &empty is explicitly cast to *some_func.

Might be related to type hints somehow.

Relevant commits: f2723ad7 - Make pointer/slice assignability rules more strict

Status
REPORTED
Submitter
~yerinalexey
Assigned to
No-one
Submitted
1 year, 3 months ago
Updated
a month ago
Labels
design harec spec

~sebsite 1 year, 3 months ago

This specific problem happens because *unaliased_fn isn't assignable to *aliased_fn, but when unary & expressions and alloc expressions have type *unaliased_fn and are given a type hint of *aliased_fn, they can convert. This is needed since function declarations can't have aliased types, and a cast shouldn't be required here. But this conversion doesn't happen when the type hint is a tagged union. Maybe we could just make *unaliased_fn assignable to *aliased_fn as a special case? That might be the best option.

~ecs 1 year, 3 months ago

i'd prefer to try to make this work with tagged unions

Register here or Log in to comment, or comment via email.