wiz-lang / wiz

A high-level assembly language for writing homebrew software and games on retro console platforms.
http://wiz-lang.org/
Other
409 stars 40 forks source link

Function types with arguments cannot be assigned to constants #76

Closed Bananattack closed 3 years ago

Bananattack commented 4 years ago

Given the following function:

func foo(bar : u16 in hl) { ... }

the following things happen when you declare a constant to hold a pointer to foo.

// CRASH: implicit assignment of functions to constant
const func_pointer = foo;
// CRASH: implicit assignment of array of functions to constant
const func_pointers = [foo, foo];
// BUG: type error assumes functions are incompatible
// but error message lists the same signature twice,
const func_pointer_explicit : func(u16 in hl) = foo;
// BUG: type error assumes functions are incompatible
// but error message lists the same signature twice,
const func_pointers_explicit : [func(u16 in hl)] = [foo, foo];

The following assignments work (but now the func pointer needs to be casted back when invoking it)

const func_pointer_casted = foo as func;
const func_pointer_explicit_casted : func = foo as func;
const func_pointers_casted = [foo as func, foo as func];
const func_pointers_explicit_casted : [func] = [foo as func, foo as func];

Fix the crash on implicitly typed constants, and the failure to recognize function expressions that exactly conform to the constant's explicit type signature.