-
Notifications
You must be signed in to change notification settings - Fork 68
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
Type Usage Consistency (2) #548
Conversation
|
||
test('Interfaces should only be able to extend inferred interfaces', async () => { | ||
const validationResult = await validate(` | ||
grammar G |
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.
I would vote for speaking names, it is hard to read
@Lotes updated that test message you pointed out, should be clearer now. |
packages/langium/test/grammar/langium-grammar-validator.test.ts
Outdated
Show resolved
Hide resolved
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.
LGTM 👍
|
||
// just for the sake of generating a pair of inferred interfaces | ||
InferredI1: 'InferredI1' InferredI1=ID; | ||
InferredI2: 'InferredI2' InferredI2=ID; |
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.
Confusing… rule name equal to assignment property?
// we can extend an inferred type that has no parent | ||
interface DeclaredExtendsInferred1 extends InferredI2 {} | ||
|
||
// we can extend an inferred type that extends other inferred types |
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.
Comments could be the name of the new test.
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.
Comments have to explain, why something is what it is. I think we should form a code so that it is easy to read without checking comments… Comments can outdate, very fast.
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.
A huge improvement around readibility. I skipped the initial version because it would have taken some effort, to understand what is important. Nice!
Bringing this in w/ the prior approval, just made the tests a little more unit-esque. |
Closes #429 (again) by extending the same super type checks done for declared types to inferred super types, extending upon the existing checks that were first applied for this issue. These checks include a warning against extending declared types by inferred types. For more details on why this is an issue, see the discussion in the original issue, which has some good conversation on the issue.
This was done by tapping into the inferred type collection already in the type system, but is only applied to a singular ParserRule. This gives enough information to be able to determine whether a type union would be ultimately generated, and in such a case we can give a validation error. In the case where no type union is generated, we can assume that an interface would be generated, and can instead apply a warning.
Hopefully this achieves the original goals without introducing too much overhead by pulling in some of the type validation logic. Ideally, it would be nice to keep those two steps more separate, but this seemed better than trying to duplicate some of the raw AST type inference logic in the grammar validation phase.