Skip to content

Commit

Permalink
Prioritize error message reporting unknown field.
Browse files Browse the repository at this point in the history
This suppresses some non-interesting follow-up errors.

Closes #1792.
  • Loading branch information
rsmmr committed Oct 16, 2024
1 parent e529e9b commit cbd269a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spicy/toolchain/src/ast/operators/unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void checkName(hilti::expression::ResolvedOperator* op) {
auto i = op->op0()->type()->type()->as<type::Unit>()->itemByName(id);

if ( ! i )
op->addError(hilti::util::fmt("unit does not have field '%s'", id));
op->addError(hilti::util::fmt("unit does not have field '%s'", id), node::ErrorPriority::High);
}


Expand Down
3 changes: 3 additions & 0 deletions tests/Baseline/spicy.types.unit.unknown-field-2/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
[error] <...>/unknown-field.spicy:12:16-12:23: unit does not have field 'tss'
[error] spicyc: aborting after errors
19 changes: 18 additions & 1 deletion tests/spicy/types/unit/unknown-field.spicy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @TEST-EXEC-FAIL: spicyc -p %INPUT >output 2>&1
# @TEST-EXEC: btest-diff output
#
# @TEST-DOC: Check that we get a proper error message when trying to access an unknown unit field; regression test for #1790
# @TEST-DOC: Check that we get a proper error message when trying to access an unknown unit field; regression test for #1790 and #1792

module Test;

Expand All @@ -13,3 +13,20 @@ type Msg = unit {
self.x = self.bar_;
}
};

# @TEST-START-NEXT

module Test;

type T = unit() {
x: uint8;
};

public type U = unit() {
len: uint32;

ts: T[] &size=self.len {
for ( e in self.tss )
print e.x;
}
};

0 comments on commit cbd269a

Please sign in to comment.