Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide proper error message when trying access an unknown unit field. #1889

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -31,7 +31,7 @@ QualifiedType* itemType(hilti::Builder* builder, const Expressions& operands) {
else if ( auto bitrange = unit->findRangeInAnonymousBitField(id).second )
return bitrange->itemType();
else
return builder->qualifiedType(builder->typeAuto(), hilti::Constness::Const);
return builder->qualifiedType(builder->typeUnknown(), hilti::Constness::Const);
}

QualifiedType* contextResult(hilti::Builder* builder, const Expressions& operands, hilti::Constness constness) {
Expand Down
2 changes: 1 addition & 1 deletion spicy/toolchain/src/ast/types/unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static std::pair<unit::item::Field*, hilti::type::bitfield::BitRange*> findRange
if ( ! field->isAnonymous() )
continue;

auto t = field->itemType()->type()->tryAs<hilti::type::Bitfield>();
auto t = field->originalType()->type()->tryAs<hilti::type::Bitfield>();
if ( ! t )
continue;

Expand Down
3 changes: 3 additions & 0 deletions tests/Baseline/spicy.types.unit.unknown-field/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:13:14-13:22: unit does not have field 'bar_'
[error] spicyc: aborting after errors
15 changes: 15 additions & 0 deletions tests/spicy/types/unit/unknown-field.spicy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# @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

module Test;

type Msg = unit {
var x: uint16;
bar: uint16;

on %done {
self.x = self.bar_;
}
};