-
Notifications
You must be signed in to change notification settings - Fork 179
Add error message for E0532 #3118
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,31 @@ void | |
TypeCheckPattern::visit (HIR::PathInExpression &pattern) | ||
{ | ||
infered = TypeCheckExpr::Resolve (&pattern); | ||
|
||
/* | ||
* We are compiling a PathInExpression, which can't be a Struct or Tuple | ||
* pattern. We should check that the declaration we are referencing IS NOT a | ||
* struct pattern or tuple with values. | ||
*/ | ||
|
||
rust_assert (infered->get_kind () == TyTy::TypeKind::ADT); | ||
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (infered); | ||
|
||
HirId variant_id = UNKNOWN_HIRID; | ||
bool ok | ||
= context->lookup_variant_definition (pattern.get_mappings ().get_hirid (), | ||
&variant_id); | ||
rust_assert (ok); | ||
|
||
TyTy::VariantDef *variant = nullptr; | ||
ok = adt->lookup_variant_by_id (variant_id, &variant); | ||
|
||
TyTy::VariantDef::VariantType vty = variant->get_variant_type (); | ||
|
||
if (vty != TyTy::VariantDef::VariantType::NUM) | ||
rust_error_at ( | ||
pattern.get_final_segment ().get_locus (), ErrorCode::E0532, | ||
"expected unit struct, unit variant or constant, found tuple variant"); | ||
Comment on lines
+69
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error message seems incorrect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy with this. I only put it in because its what rustc uses |
||
} | ||
|
||
void | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
enum State { | ||
Succeeded, | ||
Failed(u32), | ||
} | ||
|
||
fn print_on_failure(state: &State) { | ||
match *state { | ||
State::Succeeded => (), | ||
State::Failed => (), // { dg-error "expected unit struct, unit variant or constant, found tuple variant" } | ||
_ => () | ||
} | ||
} | ||
|
||
fn main() { | ||
let b = State::Failed(1); | ||
|
||
print_on_failure(&b); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
enum State { | ||
Succeeded, | ||
Failed { x: u32 }, | ||
} | ||
|
||
fn print_on_failure(state: &State) { | ||
match *state { | ||
State::Succeeded => (), | ||
State::Failed => (), // { dg-error "expected unit struct, unit variant or constant, found tuple variant" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this should say "found unit variant" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you are also right too. I feel a bit weird for this message. |
||
_ => () | ||
} | ||
} | ||
|
||
fn main() { | ||
let b = State::Failed{x: 1}; | ||
|
||
print_on_failure(&b); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it is okay that patterns reference non-ADT const items.