mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
- When encountering a foreach over a ZString* it would not properly emit a compilation error, but hit an assert #2573.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
- Compiler assert with const enum based on vector #2566
|
||||
- Fix to `Path` handling `c:\foo` and `\home` parent. #2569
|
||||
- Fix appending to `c:\` or `\` #2569.
|
||||
- When encountering a foreach over a `ZString*` it would not properly emit a compilation error, but hit an assert #2573.
|
||||
|
||||
### Stdlib changes
|
||||
|
||||
|
||||
@@ -1546,6 +1546,7 @@ static inline bool sema_analyse_foreach_stmt(SemaContext *context, Ast *statemen
|
||||
RETURN_SEMA_ERROR(var, "Add an explicit type to the variable if you want to iterate over an initializer list.");
|
||||
}
|
||||
|
||||
Type *original_type = enumerator->type;
|
||||
// In the case of a single `*`, then we will implicitly dereference that pointer.
|
||||
if (canonical->type_kind == TYPE_POINTER)
|
||||
{
|
||||
@@ -1555,6 +1556,7 @@ static inline bool sema_analyse_foreach_stmt(SemaContext *context, Ast *statemen
|
||||
RETURN_SEMA_ERROR(enumerator, "It is not possible to enumerate an expression of type %s.", type_quoted_error_string(enumerator->type));
|
||||
}
|
||||
if (!sema_expr_rewrite_insert_deref(context, enumerator)) return false;
|
||||
canonical = enumerator->type->canonical;
|
||||
}
|
||||
|
||||
// At this point we should have dereferenced any pointer or bailed.
|
||||
@@ -1600,7 +1602,7 @@ static inline bool sema_analyse_foreach_stmt(SemaContext *context, Ast *statemen
|
||||
if (value_type) goto SKIP_OVERLOAD;
|
||||
|
||||
// Otherwise this is an error.
|
||||
RETURN_SEMA_ERROR(enumerator, "It's not possible to enumerate an expression of type %s.", type_quoted_error_string(enumerator->type));
|
||||
RETURN_SEMA_ERROR(enumerator, "It's not possible to enumerate an expression of type %s.", type_quoted_error_string(original_type));
|
||||
}
|
||||
// If we want the value "by ref" and there isn't a &[], then this is an error.
|
||||
if (!by_ref && value_by_ref)
|
||||
|
||||
9
test/test_suite/statements/foreach_zstring.c3
Normal file
9
test/test_suite/statements/foreach_zstring.c3
Normal file
@@ -0,0 +1,9 @@
|
||||
module get_environ;
|
||||
import std;
|
||||
|
||||
fn void main(String[] args)
|
||||
{
|
||||
ZString* environ_arr = std::os::posix::environ;
|
||||
foreach (idx, ZString &envvar : environ_arr) // #error: It's not possible to enumerate an expression of type 'ZString*'
|
||||
{}
|
||||
}
|
||||
Reference in New Issue
Block a user