encore
encore copied to clipboard
Implicitly imported trait and local class get mingled
In the following code, parts of definitions in locally defined class C.M
get added into the implicitly imported trait A.M
, resulting in undeclared identifier bugs in the generated C code.
Consider the following three classes.
A.enc
:
module A
read trait M
end
B.enc
:
module B
import A
class T : M
end
and C.enc
:
import B
read class M
def foo() : int
10
end
end
active class Main
def main() : unit
println("{}", (new M).foo())
end
end
Trait A.M
is not explicitly imported, so there seems to be no clash between it and C.M
.
Compilation results in the following error when compiling the generated C:
McIlroy:BuggyVersion dave$ ../../../../release/encorec C.enc
C_src/T.encore.c:8:10: error: use of undeclared identifier '_ENC__MSG__A_M_foo';
did you mean '_ENC__FUT_MSG__C_M_foo'?
case _ENC__MSG__A_M_foo:
^~~~~~~~~~~~~~~~~~
_ENC__FUT_MSG__C_M_foo
C_src/header.h:256:3: note: '_ENC__FUT_MSG__C_M_foo' declared here
_ENC__FUT_MSG__C_M_foo,
^
C_src/T.encore.c:10:14: error: use of undeclared identifier
'_enc__method__B_T_foo'; did you mean '_enc__method__C_M_foo'?
return _enc__method__B_T_foo;
^~~~~~~~~~~~~~~~~~~~~
_enc__method__C_M_foo
C_src/header.h:1304:9: note: '_enc__method__C_M_foo' declared here
int64_t _enc__method__C_M_foo(pony_ctx_t**, _enc__class__C_M_t*, pony_type_t**);
^
C_src/T.encore.c:13:10: error: use of undeclared identifier
'_ENC__MSG__A_M_init'; did you mean '_ENC__FUT_MSG__C_M_init'?
case _ENC__MSG__A_M_init:
^~~~~~~~~~~~~~~~~~~
_ENC__FUT_MSG__C_M_init
C_src/header.h:257:3: note: '_ENC__FUT_MSG__C_M_init' declared here
_ENC__FUT_MSG__C_M_init,
^
3 errors generated.
*** Compilation failed with exit code 1 ***
What this means is that (part of) the definitions in C.M
, namely the presence of an init
method and a foo
method, were added into the dispatch function for trait A.M
, but no such methods exist for A.M
.
A straightforward workaround is to rename one of the M
s.
This problem occurs in development
.