gracelang/minigrace

No type checking when a method's body is just a variable name

IsaacOscar opened this issue · 2 comments

Consideer this code:

method foo(x: interface{foo})->interface{bar} { x }
foo(object{})

Runing this through mgc causes no runtime errors.
However if I change foo's body to {done; x}. I get runtime errors as expected.

Note this happens whenever the method body is a single variable name (even if not a method paramater), and effects both paramater and return type checks.

This is deliberate — its an optimisation to make simple accessors reasonably fast. Maybe this is misguided?

Commit d2ae13d restricts this optimization to methods that don't have parameters (and are not once methods). There is now a test for this case in t020 test case "once methods and accessor methods".