mirror of
https://github.com/ziglang/zig.git
synced 2026-01-30 19:23:37 +00:00
commit
697c4ffd41
@ -1625,6 +1625,16 @@ test "tokenizer - UTF-8 BOM is recognized and skipped" {
|
||||
});
|
||||
}
|
||||
|
||||
test "correctly parse pointer assignment" {
|
||||
testTokenize("b.*=3;\n", [_]Token.Id{
|
||||
Token.Id.Identifier,
|
||||
Token.Id.PeriodAsterisk,
|
||||
Token.Id.Equal,
|
||||
Token.Id.IntegerLiteral,
|
||||
Token.Id.Semicolon,
|
||||
});
|
||||
}
|
||||
|
||||
fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {
|
||||
var tokenizer = Tokenizer.init(source);
|
||||
for (expected_tokens) |expected_token_id| {
|
||||
|
||||
@ -7050,16 +7050,12 @@ check: switch (const_val->special) {
|
||||
case ZigTypeIdEnum:
|
||||
return bigint_to_llvm_const(get_llvm_type(g, type_entry), &const_val->data.x_enum_tag);
|
||||
case ZigTypeIdFn:
|
||||
if (const_val->data.x_ptr.special == ConstPtrSpecialFunction) {
|
||||
assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
|
||||
return fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry);
|
||||
} else if (const_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
|
||||
LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
|
||||
uint64_t addr = const_val->data.x_ptr.data.hard_coded_addr.addr;
|
||||
return LLVMConstIntToPtr(LLVMConstInt(usize_type_ref, addr, false), get_llvm_type(g, type_entry));
|
||||
} else {
|
||||
if (const_val->data.x_ptr.special == ConstPtrSpecialFunction &&
|
||||
const_val->data.x_ptr.mut != ConstPtrMutComptimeConst) {
|
||||
zig_unreachable();
|
||||
}
|
||||
// Treat it the same as we do for pointers
|
||||
return gen_const_val_ptr(g, const_val, name);
|
||||
case ZigTypeIdPointer:
|
||||
return gen_const_val_ptr(g, const_val, name);
|
||||
case ZigTypeIdErrorUnion:
|
||||
|
||||
@ -559,3 +559,9 @@ test "peer cast *[0]T to []const T" {
|
||||
var y = if (b) &[0]u8{} else buf;
|
||||
expect(mem.eql(u8, "abcde", y));
|
||||
}
|
||||
|
||||
var global_array: [4]u8 = undefined;
|
||||
test "cast from array reference to fn" {
|
||||
const f = @ptrCast(extern fn () void, &global_array);
|
||||
expect(@ptrToInt(f) == @ptrToInt(&global_array));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user