Skip to content
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

Merged
merged 8 commits into from
Jul 12, 2022
Merged

Type Usage Consistency (2) #548

merged 8 commits into from
Jul 12, 2022

Conversation

montymxb
Copy link
Contributor

@montymxb montymxb commented Jun 17, 2022

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.


test('Interfaces should only be able to extend inferred interfaces', async () => {
const validationResult = await validate(`
grammar G
Copy link
Contributor

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

@montymxb montymxb requested a review from Lotes June 30, 2022 12:39
@montymxb
Copy link
Contributor Author

@Lotes updated that test message you pointed out, should be clearer now.

@montymxb montymxb requested a review from msujew June 30, 2022 12:39
Copy link
Member

@msujew msujew left a 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;
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

@Lotes Lotes Jul 1, 2022

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.

Copy link
Contributor

@Lotes Lotes left a 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!

@montymxb
Copy link
Contributor Author

Bringing this in w/ the prior approval, just made the tests a little more unit-esque.

@montymxb montymxb merged commit bfe6d6f into main Jul 12, 2022
@montymxb montymxb deleted the montymxb/type-usage-consistency2 branch July 12, 2022 10:43
@msujew msujew added this to the v0.5.0 milestone Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consistency of type usage
3 participants