Skip to content

Commit 7539976

Browse files
committed
fwd: Make some errors more friendly
1 parent a4d8488 commit 7539976

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

asteria/compiler/statement_sequence.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ do_accept_identifier_opt(Token_Stream& tstrm, bool user_decl)
6262
if(!qtok)
6363
return nullopt;
6464

65+
if(user_decl && qtok->is_keyword())
66+
throw Compiler_Error(xtc_format,
67+
compiler_status_keyword_not_declarable, qtok->sloc(),
68+
"Keyword `$1` not user-declarable", qtok->as_keyword_c_str());
69+
6570
// See whether it is an identifier.
6671
if(!qtok->is_identifier())
6772
return nullopt;

asteria/fwd.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ describe_compiler_status(Compiler_Status status) noexcept
376376
case compiler_status_interval_closure_expected:
377377
return "`)` or `]` expected";
378378

379+
case compiler_status_keyword_not_declarable:
380+
return "keyword not declarable";
381+
379382
default:
380383
return "[unknown compiler status]";
381384
}

asteria/fwd.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ enum Compiler_Status : uint32_t
742742
compiler_status_multiple_default = 3004,
743743
compiler_status_duplicate_name_in_structured_binding = 3005,
744744
compiler_status_duplicate_name_in_parameter_list = 3006,
745+
compiler_status_keyword_not_declarable = 3007,
745746
};
746747

747748
ROCKET_CONST

0 commit comments

Comments
 (0)