-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respect the declared/returned type of data type rules, which is relevant for the default value converter #1500
Respect the declared/returned type of data type rules, which is relevant for the default value converter #1500
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the lint CI, it seems like the change leads to a regression. The generated names actually change from the data type name to their declared types. I'm suprised we don't have actual tests for that. Do you mind adding some?
As for the change, I would recommend something else:
- Create a new
getRuleTypeName
function that reuses the old behavior of thegetRuleType
function. It should be used everywhere except for theValueConverter
. - Add appropriate comments to explain the difference between those two functions.
getRuleType
should be used during the runtime, whilegetRuleTypeName
is useful for code generation and the internal type system.
37c4924
to
cf535e2
Compare
Thanks @msujew for your review! I created two functions, one to be used at runtime and the other one at development time. However, there are already test cases which check the generated code for data type rules with return type: Any ideas? |
@JohannesMeierSE These tests don't test the generated property types. For example:
is supposed to generate:
|
Thanks for the suggestion @msujew! I added two test cases which test properties with data types which have an explicit return type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
packages/langium/test/grammar/type-system/type-validator.test.ts
Outdated
Show resolved
Hide resolved
…he default value converter
8864a25
to
eb60e34
Compare
This PR contributes:
This issue was found in a real-world application, where a data type rule (with
returns number
) which referred to a terminal rule (withreturns number
) produced astring
value at runtime in the AST (while the generated property in the TypeScript interface had the correct typenumber
). This conforms to the "number case" in the new test case. The cases for string and boolean are added only to be more complete.This issue is not related to #1478.