Void* should never deref and should allow methods to be attached to it.

This commit is contained in:
Christoffer Lerno
2023-10-27 00:10:59 +02:00
parent a0bc03a9f5
commit e17bb5f321
7 changed files with 11 additions and 13 deletions

View File

@@ -362,6 +362,7 @@ macro uint bool.hash(bool b) => (uint)b;
macro uint typeid.hash(typeid t) => ((ulong)(uptr)t).hash();
macro uint String.hash(String c) => (uint)fnv32a::encode(c);
macro uint char[].hash(char[] c) => (uint)fnv32a::encode(c);
macro uint void*.hash(void* ptr) => ((ulong)(uptr)ptr).hash();
module std::core::builtin @if((env::LINUX || env::DARWIN) && env::COMPILER_SAFE_MODE && env::DEBUG_SYMBOLS);
import libc;

View File

@@ -282,10 +282,10 @@ macro void DString.append(&self, value)
self.append_char32(value);
$default:
$switch
$case $assignable(value, Char32):
self.append_char32(value);
$case $assignable(value, String):
self.append_chars(value);
$case $defined((Char32)value):
self.append_char32((Char32)value);
$case $defined((String)value):
self.append_chars((String)value);
$default:
$error "Unsupported type for append use printf instead.";
$endswitch

View File

@@ -136,7 +136,7 @@ macro usz! print_gen(self, x)
$case DString:
return self.write(x.str_view());
$default:
$if $assignable(x, String):
$if $defined((String)x):
return self.write((String)x);
$else
return printf("%s", x);

View File

@@ -2945,10 +2945,7 @@ static bool sema_analyse_macro_method(SemaContext *context, Decl *decl)
Type *parent_type = parent_type_info->type;
if (!type_may_have_method(parent_type))
{
SEMA_ERROR(parent_type_info,
"Methods can not be associated with '%s'",
type_to_error_string(parent_type));
return false;
RETURN_SEMA_ERROR(parent_type_info, "Methods can not be associated with '%s'", type_to_error_string(parent_type));
}
if (!vec_size(decl->func_decl.signature.params))
{

View File

@@ -3984,8 +3984,7 @@ static inline bool sema_expr_analyse_access(SemaContext *context, Expr *expr, bo
// 7. Is this a pointer? If so we insert a deref.
Type *underlying_type = type_no_optional(parent->type)->canonical;
bool is_pointer = underlying_type->type_kind == TYPE_POINTER;
if (is_pointer)
if (underlying_type->type_kind == TYPE_POINTER && underlying_type != type_voidptr)
{
if (!sema_cast_rvalue(context, parent)) return false;
expr_rewrite_insert_deref(expr->access_expr.parent);

View File

@@ -1879,9 +1879,10 @@ bool type_may_have_method(Type *type)
return true;
case TYPE_TYPEDEF:
UNREACHABLE
case TYPE_POINTER:
return type == type_voidptr;
case TYPE_POISONED:
case TYPE_VOID:
case TYPE_POINTER:
case TYPE_FUNC:
case TYPE_UNTYPED_LIST:
case TYPE_OPTIONAL:

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.689"
#define COMPILER_VERSION "0.4.690"