File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -2884,6 +2884,16 @@ absl::StatusOr<Expr*> Parser::BuildMacroOrInvocation(
28842884 parametrics);
28852885 }
28862886
2887+ if (name == " read" || name == " write" ) {
2888+ if (!module_->attributes ().contains (
2889+ ModuleAttribute::kExplicitStateAccess )) {
2890+ return ParseErrorStatus (
2891+ span,
2892+ absl::StrFormat (
2893+ " %s() requires #![feature(explicit_state_access)]" , name));
2894+ }
2895+ }
2896+
28872897 if (name == " zero!" ) {
28882898 if (parametrics.size () != 1 ) {
28892899 return ParseErrorStatus (
Original file line number Diff line number Diff line change @@ -3498,6 +3498,26 @@ TEST_F(ParserTest, ParseExplicitStateAccessAttribute) {
34983498 testing::ElementsAre (ModuleAttribute::kExplicitStateAccess ));
34993499}
35003500
3501+ TEST_F (ParserTest, ParseExplicitStateAccessNoFeatureFlag) {
3502+ constexpr std::string_view kProgram = R"(
3503+ proc foo {
3504+ config() { () }
3505+ init { u32: 10 }
3506+ next(state: u32) {
3507+ read(state);
3508+ write(state, state + 1);
3509+ state
3510+ }
3511+ }
3512+ )" ;
3513+ Scanner s{file_table_, Fileno (0 ), std::string (kProgram )};
3514+ Parser parser{" test" , &s};
3515+ EXPECT_THAT (parser.ParseModule (),
3516+ StatusIs (absl::StatusCode::kInvalidArgument ,
3517+ HasSubstr (" read() requires "
3518+ " #![feature(explicit_state_access)]" )));
3519+ }
3520+
35013521TEST_F (ParserTest, ExplicitStateAccessProcNextReturnsEmptyTuple) {
35023522 constexpr std::string_view kProgram = R"( #![feature(explicit_state_access)]
35033523proc simple {
You can’t perform that action at this time.
0 commit comments