Reason: Better priority for object/record keys

Created on 26 Aug 2016  路  6Comments  路  Source: reasonml/reason

// This errors:
type foo = {open: false};
// another:
bla.open;

In general, it'd be great if record/obj keys have "higher priority" than build-in keywords? Is that a good idea? If not, at least better errors.

Most helpful comment

might be useful for external JS objects too. it's not uncommon to have "type" as a property name, and jsObj##type throws, forcing to create a FFI

All 6 comments

I think this is doable even if a bit tricky. You have to create a new parse rule for identifiers suitable for use in places such as keys/record labels. Those identifiers would be the union of typical identifiers, and other tokens. We'd then just need to make sure that the compiler itself doesn't complain when handed an AST with record labels matching certain tokens - and if so, we'd have to do some escaping.

I think that's probably not a great idea? keywords should be keywords.
but let's ditch open from the default reason syntax :D (we can just have it be import * from SomeMod)

Yeah, maybe by trimming out the keywords, we can achieve the same effect.

might be useful for external JS objects too. it's not uncommon to have "type" as a property name, and jsObj##type throws, forcing to create a FFI

Same as https://github.com/facebook/reason/issues/824#issuecomment-338384372 :

  • ocaml compatibility lost
  • punning gets messy

Besides that, it could be implemented.

Yeah then let's not for now. We'll have better errors for these soon

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ostera picture ostera  路  3Comments

rickyvetter picture rickyvetter  路  3Comments

gustavopinto picture gustavopinto  路  3Comments

chenglou picture chenglou  路  3Comments

chenglou picture chenglou  路  3Comments