Skip to content

Commit

Permalink
[parser] forbid reserved types in opaque type
Browse files Browse the repository at this point in the history
Summary: `opaque type string = number` would overwrite the `string` builtin. reserved types should be disallowed.

Reviewed By: samwgoldman

Differential Revision: D6199767

fbshipit-source-id: f0f5bdf44d8cff0d444381747f0ebb5a94df3ffa
  • Loading branch information
mroch authored and facebook-github-bot committed Oct 31, 2017
1 parent 831243f commit 74189a0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser/statement_parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ module Statement
Expect.token env T_OPAQUE;
Expect.token env T_TYPE;
Eat.push_lex_mode env Lex_mode.TYPE;
let id = Parse.identifier env in
let id = Type.type_identifier env in
let typeParameters = Type.type_parameter_declaration_with_defaults env in
let supertype = match Peek.token env with
| T_COLON ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
opaque type string = number;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"errors":[
{
"loc":{"source":null,"start":{"line":1,"column":12},"end":{"line":1,"column":18}},
"message":"Unexpected reserved type"
}
],
"type":"Program",
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":28}},
"range":[0,28],
"body":[
{
"type":"OpaqueType",
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":28}},
"range":[0,28],
"id":{
"type":"Identifier",
"loc":{"source":null,"start":{"line":1,"column":12},"end":{"line":1,"column":18}},
"range":[12,18],
"name":"string",
"typeAnnotation":null,
"optional":false
},
"typeParameters":null,
"impltype":{
"type":"NumberTypeAnnotation",
"loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":27}},
"range":[21,27]
},
"supertype":null
}
],
"comments":[]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
opaque type switch = number;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"type":"Program",
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":28}},
"range":[0,28],
"body":[
{
"type":"OpaqueType",
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":28}},
"range":[0,28],
"id":{
"type":"Identifier",
"loc":{"source":null,"start":{"line":1,"column":12},"end":{"line":1,"column":18}},
"range":[12,18],
"name":"switch",
"typeAnnotation":null,
"optional":false
},
"typeParameters":null,
"impltype":{
"type":"NumberTypeAnnotation",
"loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":27}},
"range":[21,27]
},
"supertype":null
}
],
"comments":[]
}

0 comments on commit 74189a0

Please sign in to comment.