Skip to content
This repository has been archived by the owner on Jun 14, 2022. It is now read-only.

disallowing map, vector and open identifiers is a bad idea #19

Open
shviller opened this issue Jul 8, 2017 · 2 comments
Open

disallowing map, vector and open identifiers is a bad idea #19

shviller opened this issue Jul 8, 2017 · 2 comments

Comments

@shviller
Copy link

shviller commented Jul 8, 2017

A seemingly innocuous

--# assume File.open:	method() --> boolean
--# assume File.write:	method(string, integer?) --> (boolean, string?)
--# assume File.close:	method() --> boolean

leads to

.\love.lua.kailua:35:17: 35:21 [Error] Expected a name, got a keyword `open`
35 | --# assume File.open:   method() --> boolean
   |                 ^^^^

Similarly to open being a rather popular name, map is a widely-used function with entirely idiomatic semantics (see Underscore.lua, Penlight, Moses, Lua Functional, Lume...), and given that you'd need to use --# assume on it on nearly any invocation (similarly to #18), kailua's inability to stomach any annotation that mentions map as an identifier severely limits its usefulness.

vector also systematically occurs as an identifier name in certain subject domains.

@lifthrasiir
Copy link
Contributor

lifthrasiir commented Jul 9, 2017

Every name can be escaped with backquotes (`) in the Kailua context, so this is merely an inconvenience. The different set of reserved words in the Kailua context had been also useful for future-proofing reserved word additions (e.g. an unescaped goto is a hard error in the Kailua context even when you are using it in Lua 5.1).

That said, we can probably make several keywords usable as identifiers when they will never occur as a keyword at that position even in the future. Are only open, map and vector problematic? map and vector as keywords were also a kind of transitionary syntaxes (in place of generic types) so they can be possibly removed from a set of keywords, without breaking any existing code.

I also plan to expand the documentation (instead of the current sorta ad-hoc overview :-) to describe such things in more detail in the future.

@shviller
Copy link
Author

shviller commented Jul 9, 2017

Escaping with ` works great, thanks! In my limited experience, I only ran into trouble with open, map and vector, but I can imagine method tripping up someone trying to implement yet another OOP system in Lua.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants