Skip to content

Commit 419b0e9

Browse files
committed
Add new reserved keywords. Closes #2182.
1 parent c9840c9 commit 419b0e9

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

libsolidity/parsing/Token.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,22 +221,43 @@ namespace solidity
221221
/* Keywords reserved for future use. */ \
222222
K(Abstract, "abstract", 0) \
223223
K(After, "after", 0) \
224+
K(Alias, "alias", 0) \
225+
K(Apply, "apply", 0) \
226+
K(Auto, "auto", 0) \
224227
K(Case, "case", 0) \
225228
K(Catch, "catch", 0) \
229+
K(Const, "const", 0) \
230+
K(Constructor, "constructor", 0) \
226231
K(Default, "default", 0) \
232+
K(Define, "define", 0) \
233+
K(Fallback, "fallback", 0) \
227234
K(Final, "final", 0) \
235+
K(Immutable, "immutable", 0) \
236+
K(Implements, "implements", 0) \
228237
K(In, "in", 0) \
229238
K(Inline, "inline", 0) \
230239
K(Let, "let", 0) \
240+
K(Macro, "macro", 0) \
231241
K(Match, "match", 0) \
242+
K(Mutable, "mutable", 0) \
232243
K(NullLiteral, "null", 0) \
233244
K(Of, "of", 0) \
245+
K(Override, "override", 0) \
246+
K(Promise, "promise", 0) \
247+
K(Reference, "reference", 0) \
234248
K(Relocatable, "relocatable", 0) \
249+
K(Sealed, "sealed", 0) \
250+
K(Sizeof, "sizeof", 0) \
235251
K(Static, "static", 0) \
252+
K(Supports, "supports", 0) \
236253
K(Switch, "switch", 0) \
254+
K(Topic, "topic", 0) \
237255
K(Try, "try", 0) \
238256
K(Type, "type", 0) \
257+
K(Typedef, "typedef", 0) \
239258
K(TypeOf, "typeof", 0) \
259+
K(Unchecked, "unchecked", 0) \
260+
\
240261
/* Illegal token - not able to scan. */ \
241262
T(Illegal, "ILLEGAL", 0) \
242263
\

test/libsolidity/SolidityParser.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,56 @@ BOOST_AUTO_TEST_CASE(constant_is_keyword)
11641164
CHECK_PARSE_ERROR(text, "Expected identifier");
11651165
}
11661166

1167+
BOOST_AUTO_TEST_CASE(keyword_is_reserved)
1168+
{
1169+
auto keywords = {
1170+
"abstract",
1171+
"after",
1172+
"alias",
1173+
"apply",
1174+
"auto",
1175+
"case",
1176+
"catch",
1177+
"const",
1178+
"constructor",
1179+
"default",
1180+
"define",
1181+
"fallback",
1182+
"final",
1183+
"immutable",
1184+
"implements",
1185+
"in",
1186+
"inline",
1187+
"let",
1188+
"macro",
1189+
"match",
1190+
"mutable",
1191+
"null",
1192+
"of",
1193+
"override",
1194+
"promise",
1195+
"reference",
1196+
"relocatable",
1197+
"sealed",
1198+
"sizeof",
1199+
"static",
1200+
"supports",
1201+
"switch",
1202+
"topic",
1203+
"try",
1204+
"type",
1205+
"typedef",
1206+
"typeof",
1207+
"unchecked"
1208+
};
1209+
1210+
1211+
for (const auto& keyword : keywords) {
1212+
auto text = std::string("contract ") + keyword + " {}";
1213+
CHECK_PARSE_ERROR(text.c_str(), "Expected identifier");
1214+
}
1215+
}
1216+
11671217
BOOST_AUTO_TEST_CASE(var_array)
11681218
{
11691219
char const* text = R"(

0 commit comments

Comments
 (0)