question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consistency of type usage

See original GitHub issue

See https://github.com/langium/langium/pull/406#discussion_r810922786: we should validate usages of types for consistency. For example, this is not valid because Foo is not an AST node type.

type Foo = string;

Bar returns Foo: ...

The same applies to actions and extended interfaces.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
montymxbcommented, Jun 8, 2022

@pluralia @msujew while working through this problem I had an idea I wanted to run by you both. Would it be considered reasonable to prevent interfaces from extending inferred types? And by extension, just saying that declared types cannot extend inferred types.

I have some thoughts why this might be helpful:

  • it clearly separates the fact that declared types exist on a separate level from parser rules
  • we don’t have to try to report errors that stem from inferred types in this case
  • it removes having to compute inferred types (and unions) to validate existing type hierarchies
  • it supports that declared types are unambiguous in their structure and inheritance

In this way, you can make something explicit, but you cannot set it back by basing it on something inferred.

I am trying to think if this restricts anything in terms of expressiveness, but I haven’t come up with anything yet 🤔 .

1reaction
pluraliacommented, Jun 15, 2022

I like the idea, here is some thoughts.

it clearly separates the fact that declared types exist on a separate level from parser rules

We are going to implement the strict mode specially for the case.

it removes having to compute inferred types (and unions) to validate existing type hierarchies

We still have to do it for validation purposes.

One of the most important advantages of Langium is the brief prototyping: you can write a couple of parser rules and everything works out of the box. Sometimes you need to add declared types in addition to this pair of parser rules for minimal type shaping, in which case it’s no good to prohibit extending inferred types, because you would have to add more declared types, which goes against the idea of brief prototyping “as few entities in grammar as possible”.

Another point is that inferred and declared types will become semantically “unequal”: declared types can be extended, while inferred types cannot.

To summarize: I think we should do it in the strict mode only and allow it by default for brief prototyping.

We shortly discussed this problem, and @montymxb suggested using warnings when inferred types are extended by declared types. I fully support this idea: we keep prototyping brief, but at the same time notify the user when a declared type is “unstable” and can be implicitly changed because of the parent inferred type.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TYPOGRAPHY: Consistency
Consistency gives polish to a site and encourages visitors to stay by creating an expectation about the structure of a text.
Read more >
Using consistent data types
You can largely avoid conversions by using consistent data types and by giving both operands the same usage and also appropriate PICTURE specifications....
Read more >
haskell - What exactly makes a type system consistent?
In this sense of consistency, consistency means that the bottom (void) type doesn't have an inhabitant (and, thus, a derivation). That is, every ......
Read more >
How Do You Stay Brand Consistent With Your Type Styles?
Consistent brands have and use their set typography style. The most successful type incorporates multiple header styles and one paragraph style.
Read more >
Maintain Consistency and Adhere to Standards (Usability ...
To be easy to learn and use, systems should adhere to both internal and external consistency — they should use the same patterns...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found