gracelang / minigrace

Self-hosting compiler for the Grace programming language
39 stars 22 forks source link

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

Closed IsaacOscar closed 4 years ago

IsaacOscar commented 5 years ago

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.

apblack commented 5 years ago

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

apblack commented 4 years ago

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".