Closed fungiboletus closed 4 years ago
@brice-morin I'm a bit stuck with this problem, but you are the one who wrote the code generator.
I think we can't use simply the message name as a classname but what can we use instead ?
It probably appeared in 7db8763a6ab0be99eb570eb915ef9b64e43ec3fa related to #283
Should be easy to fix. Append the name of the thing where messages are defined. There should be a helper to find the containing thing. Alternatively, it should be safe to take myMsg.eContainer() and cast it as a Thing.
I am in a taxi right now, but I can have a look later on
I'm working on a fix with the name of the thing added, but I think it will still be possible to break stuff with some unlucky names.
OK, good. I will write a test meanwhile.
I tried something in 26c092a30a3fefdb8378e52a8ab72c848469ea5a but it looks like it was not as easy as I thought. Guards and probably actions are broken now.
OK, I'll have a look and run the tests
See my comment on your commit, fix, and then I can run the tests :-)
Note that I do not expect problems on guards and transitions, which use the port
and type
attributes of the classes generated from the messages.
I did change the type
attribute to also have the name of the thing at the end. I don't know whether it's required.
Guards generate broken code like this in my branch :
SafariMadnessWorkaround_null_Safari_Buffering_WaitBuffering.to(SafariMadnessWorkaround_null_Safari_Buffering_ProcessBuffering).on(Event.Timer_timeout_TimerMsgs).when((timer_timeout_TimerMsgs) => {
return timer_timeout_TimerMsgs.port === 'timer' && timer_timeout_TimerMsgs.type === 'timer_timeout_TimerMsgs' && (timer_timeout.id === this.SafariMadnessWorkaround_waitBufferingTimerId_var);
});
Yes, true, you did change the type
attribute.....
I would say it is not necessary, as a given thing should not be able, AFAIK, to include and/or define two messages with the same name. I would expect the checker to complain, and if not, the parser to yield funny results in some cases... (I just check, and it seems the cheker is happy, but the parser indeed loses its mind)
But two different things should indeed be able to define a message each, with the same name.
So, IMHO, revert the type
back to its simpler form. And be careful when you have two messages with the same name: keep them in separate things!
Well, I have been too fast in my previous comment. There is some cases where it can work, like having two things fragments, each defining a message m
. If this message m
is in a port p1
in the first fragment, and p2
in the second fragment, then you can safely include both fragments in a given thing, and the parser will work as expected. Nevertheless, the existing logic in JS using type
and port
should also work. So, again, revert the type
back, as it will save you some changes in guards, transitions, etc :-)
type
has been reverted :-)
OK, seems like there is no regression in the tests. You can pull request and merge yourself :-)
The messages in different things with the same names will override each other.
This will generate the following
events.js
code: