boschresearch / blech

Blech is a language for developing reactive, real-time critical embedded software.
Apache License 2.0
72 stars 5 forks source link

Strange error message in type checking when calling an opaque singleton #47

Closed schorg closed 3 years ago

schorg commented 3 years ago

Describe the bug Type checker issues a strange error message

10:21:35 [Main] performing type checking on .\useopaquesingleton.blc
error: This is a function call to an activity. Did you mean 'run f ...'?
 --> .\useopaquesingleton.blc:6:5 [typing]

when it finds a function call to an opaque singleton.

To Reproduce Assume the following modules

module exposes g

singleton function f() end

function g()   
     f()
end

Imported from the following module

import os "opaquesingleton"

module exposes h

singleton function h()
    os.f()  // call to an opaque singleton
end

When we call run os.f(), the type checker generates the following error message, which is also strange.

10:23:46 [Main] performing type checking on .\useopaquesingleton.blc
error: You can only run an activity, not a function.
 --> .\useopaquesingleton.blc:6:5 [typing]

Expected behaviour Error message that explains the error. Something like "an opaque singleton cannot be called".

FriedrichGretz commented 3 years ago

The issue comes from an assumption that is no longer valid: if the type checker cannot find a function [or activity] in the dictionary of known declarations then the given QName must in fact be an activity [or function]. Because if the name did not exist at all, then the name resolution would already have thrown an error. Now, with modules, the name is actually there because it is implicitly exposed (as an opaque procedure) so the name resolution passes but it is neither a callable function nor an activity. The type checker now takes this into account, see test cases typechecker/invalid/usehiddenactivity and useopaquesingleton.