mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
A distinct inline pointer type can now participate in pointer arithmetics.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
- Fix bug where `a > 0 ? f() : g()` could cause a compiler crash if both returned `void!`.
|
||||
- `@builtin` was not respected for generic modules #1617.
|
||||
- Fix issue writing a single byte in the WriteBuffer
|
||||
- A distinct inline pointer type can now participate in pointer arithmetics.
|
||||
|
||||
### Stdlib changes
|
||||
- Add `io::MultiReader`, `io::MultiWriter`, and `io::TeeReader` structs.
|
||||
|
||||
@@ -2698,10 +2698,25 @@ INLINE CanonicalType *type_pointer_type(Type *type)
|
||||
return res->pointer;
|
||||
}
|
||||
|
||||
static inline Type *type_flat_distinct_inline(Type *type);
|
||||
|
||||
INLINE bool type_is_pointer_like(Type *type)
|
||||
{
|
||||
TypeKind kind = type->type_kind;
|
||||
return kind == TYPE_POINTER || (kind == TYPE_VECTOR && type->array.base->canonical->type_kind == TYPE_POINTER);
|
||||
if (kind == TYPE_DISTINCT)
|
||||
{
|
||||
type = type_flat_distinct_inline(type);
|
||||
kind = type->type_kind;
|
||||
}
|
||||
switch (kind)
|
||||
{
|
||||
case TYPE_POINTER:
|
||||
return true;
|
||||
case TYPE_VECTOR:
|
||||
return type_is_pointer_like(type->array.base->canonical);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
INLINE bool type_is_pointer_vector(Type *type)
|
||||
|
||||
@@ -276,7 +276,7 @@ LLVMTypeRef llvm_func_type(GenContext *context, FunctionPrototype *prototype)
|
||||
|
||||
LLVMTypeRef llvm_get_pointee_type(GenContext *c, Type *any_type)
|
||||
{
|
||||
any_type = any_type->canonical;
|
||||
any_type = type_lowering(any_type);
|
||||
ASSERT0(any_type->type_kind == TYPE_POINTER);
|
||||
if (any_type == type_voidptr) return llvm_get_type(c, type_char);
|
||||
return llvm_get_type(c, any_type->pointer);
|
||||
|
||||
7
test/test_suite/distinct/distinct_add.c3
Normal file
7
test/test_suite/distinct/distinct_add.c3
Normal file
@@ -0,0 +1,7 @@
|
||||
import std;
|
||||
fn void main()
|
||||
{
|
||||
ZString a = "abc";
|
||||
ZString b = a + 1;
|
||||
io::printfn("%s", b);
|
||||
}
|
||||
Reference in New Issue
Block a user