Skip to content

Commit

Permalink
Emit parser errors for trait functionalities not yet impelemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ymadzhunkov committed Jul 31, 2023
1 parent 3cf1109 commit 1070de6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions crates/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ fn trait_definition() -> impl NoirParser<TopLevelStatement> {
.then_ignore(just(Token::RightBrace))
.validate(|(((name, generics), where_clause), items), span, emit| {
validate_where_clause(&generics, &where_clause, span, emit);
if generics.len() > 0 || where_clause.len() > 0 {
emit(ParserError::with_reason(ParserErrorReason::TraitsAreExperimental, span));
}
TopLevelStatement::Trait(NoirTrait { name, generics, where_clause, span, items })
})
}
Expand Down Expand Up @@ -486,11 +489,15 @@ fn trait_implementation() -> impl NoirParser<TopLevelStatement> {
.then_ignore(just(Token::LeftBrace))
.then(trait_implementation_body())
.then_ignore(just(Token::RightBrace))
.validate(|args, _span, _emit| {
.validate(|args, span, emit| {
let ((other_args, where_clause), items) = args;
let (((impl_generics, trait_name), trait_generics), (object_type, object_type_span)) =
other_args;

if where_clause.len() > 0 || impl_generics.len() > 0 {
emit(ParserError::with_reason(ParserErrorReason::TraitsAreExperimental, span));
}

TopLevelStatement::TraitImpl(TraitImpl {
impl_generics,
trait_name,
Expand Down Expand Up @@ -521,10 +528,9 @@ fn where_clause() -> impl NoirParser<Vec<TraitConstraint>> {
.then_ignore(just(Token::Colon))
.then(ident())
.then(generic_type_args(parse_type()))
.validate(|((typ, trait_name), trait_generics), _span, _emit| TraitConstraint {
typ,
trait_name,
trait_generics,
.validate(|((typ, trait_name), trait_generics), span, emit| {
emit(ParserError::with_reason(ParserErrorReason::TraitsAreExperimental, span));
TraitConstraint { typ, trait_name, trait_generics}
});

keyword(Keyword::Where)
Expand Down

0 comments on commit 1070de6

Please sign in to comment.