mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Improved error messages on missing qualifier on enum value. #2260
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
- Casting to / from an enum is now possible again. No need to use `.ordinal` and `.from_ordinal`.
|
- Casting to / from an enum is now possible again. No need to use `.ordinal` and `.from_ordinal`.
|
||||||
- Inline associated enum values are deprecated, use `--use-old-enums` to re-enable them.
|
- Inline associated enum values are deprecated, use `--use-old-enums` to re-enable them.
|
||||||
- `$typeof` may return a compile time type.
|
- `$typeof` may return a compile time type.
|
||||||
|
- Improved error messages on missing qualifier on enum value. #2260
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
- mkdir/rmdir would not work properly with substring paths on non-windows platforms.
|
- mkdir/rmdir would not work properly with substring paths on non-windows platforms.
|
||||||
|
|||||||
@@ -1110,6 +1110,26 @@ static inline bool sema_expr_analyse_identifier(SemaContext *context, Type *to,
|
|||||||
// Rerun if we can't do inference.
|
// Rerun if we can't do inference.
|
||||||
if (!decl)
|
if (!decl)
|
||||||
{
|
{
|
||||||
|
if (!expr->unresolved_ident_expr.path && expr->unresolved_ident_expr.is_const && (!to || to->canonical->type_kind != TYPE_ENUM))
|
||||||
|
{
|
||||||
|
CompilationUnit **units = context->unit->module->units;
|
||||||
|
FOREACH (CompilationUnit *, unit, units)
|
||||||
|
{
|
||||||
|
FOREACH(Decl *, decl, unit->enums)
|
||||||
|
{
|
||||||
|
FOREACH(Decl *, enum_val, decl->enums.values)
|
||||||
|
{
|
||||||
|
if (enum_val->name == expr->unresolved_ident_expr.ident)
|
||||||
|
{
|
||||||
|
RETURN_SEMA_ERROR(expr, "No constant named '%s' was found in the current scope. Did you "
|
||||||
|
"mean the value '%s' of the enum '%s'? The enum type cannot be inferred%s, so in that case you need to use "
|
||||||
|
"the qualified name: '%s.%s'.",
|
||||||
|
enum_val->name, enum_val->name, decl->name, to ? " correctly" : "", decl->name, enum_val->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
decl = sema_resolve_symbol(context, expr->unresolved_ident_expr.ident, expr->unresolved_ident_expr.path, expr->span);
|
decl = sema_resolve_symbol(context, expr->unresolved_ident_expr.ident, expr->unresolved_ident_expr.path, expr->span);
|
||||||
(void)decl;
|
(void)decl;
|
||||||
ASSERT_SPAN(expr, !decl);
|
ASSERT_SPAN(expr, !decl);
|
||||||
|
|||||||
16
test/test_suite/enumerations/enum_infer_err.c3
Normal file
16
test/test_suite/enumerations/enum_infer_err.c3
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import std::io;
|
||||||
|
|
||||||
|
enum Foo
|
||||||
|
{
|
||||||
|
BAR
|
||||||
|
}
|
||||||
|
|
||||||
|
fn void test()
|
||||||
|
{
|
||||||
|
int x = BAR; // #error: type cannot be inferred correctly,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn void main()
|
||||||
|
{
|
||||||
|
io::printn(BAR); // #error: type cannot be inferred,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user