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

Optional type annotations #170

Open
erkyrath opened this issue Apr 20, 2022 · 1 comment
Open

Optional type annotations #170

erkyrath opened this issue Apr 20, 2022 · 1 comment

Comments

@erkyrath
Copy link
Contributor

erkyrath commented Apr 20, 2022

It would be nice to annotate global variables and property declarations with a type. (Could annotate --> arrays as well.) Then the compiler could generate warnings (not errors) on object definitions and statically-typable assignments.

This would be entirely opt-in. An unannotated declaration would not be type-checked, which is how Inform works today.

What's a type? At a minimum we need Number, String, Routine, Class, Dictionary, and combined types like String|Routine. Maybe specific object classes too. Can a type include "or zero"? What about "or -1"? (The library defines NULL = -1, and it's a valid value for before.) (In fact the veneer recognizes -1 in such properties.) A list of constant values for an enum?

I am not even getting into the question of how to spell these annotations.

This is difficult but potentially very helpful to authors. Inciting example:

Object obj with article 'the';

(The library wants the article property to contain a string, not a dict word.)

Idea mentioned in forum thread: https://intfiction.org/t/inform-6-compiler-does-not-give-error-when-article-property-uses-single-quotes/55512

@erkyrath
Copy link
Contributor Author

erkyrath commented Jun 8, 2022

There is one example of this in the compiler already: the built-in name property is known to contain dict words. Therefore, with name "lamp" "lantern" is interpreted as a list of dict words even though they have double quotes.

I don't know if I want to perpetuate (or perpetrate) that kind of syntax hack, but warnings are fine.

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

No branches or pull requests

1 participant