authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-05 18:50:36-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-05 18:50:36-05:00
loge621ad014e919521268d3e2c94afadbdadadb59f
treea038e0051b6d8c9b220cb2faa2918eb3f42fa909
parent97e105489085fcf4530b3944499531d76848bbd1

pass cannot assign to constant test


8 files changed, 70 insertions(+), 36 deletions(-)

example/cat/main.zig+4-4
...@@ -10,7 +10,7 @@ pub fn main(args: [][]u8) -> %void {...@@ -10,7 +10,7 @@ pub fn main(args: [][]u8) -> %void {
10 for (args[1...]) |arg| {10 for (args[1...]) |arg| {
11 if (str.eql(arg, "-")) {11 if (str.eql(arg, "-")) {
12 catted_anything = true;12 catted_anything = true;
13 cat_stream(io.stdin) %% |err| return err;13 cat_stream(&io.stdin) %% |err| return err;
14 } else if (arg[0] == '-') {14 } else if (arg[0] == '-') {
15 return usage(exe);15 return usage(exe);
16 } else {16 } else {
...@@ -24,11 +24,11 @@ pub fn main(args: [][]u8) -> %void {...@@ -24,11 +24,11 @@ pub fn main(args: [][]u8) -> %void {
24 defer %%is.close();24 defer %%is.close();
2525
26 catted_anything = true;26 catted_anything = true;
27 cat_stream(is) %% |err| return err;27 cat_stream(&is) %% |err| return err;
28 }28 }
29 }29 }
30 if (!catted_anything) {30 if (!catted_anything) {
31 cat_stream(io.stdin) %% |err| return err;31 cat_stream(&io.stdin) %% |err| return err;
32 }32 }
33 io.stdout.flush() %% |err| return err;33 io.stdout.flush() %% |err| return err;
34}34}
...@@ -40,7 +40,7 @@ fn usage(exe: []u8) -> %void {...@@ -40,7 +40,7 @@ fn usage(exe: []u8) -> %void {
40 return error.Invalid;40 return error.Invalid;
41}41}
4242
43fn cat_stream(is: io.InStream) -> %void {43fn cat_stream(is: &io.InStream) -> %void {
44 var buf: [1024 * 4]u8 = undefined;44 var buf: [1024 * 4]u8 = undefined;
4545
46 while (true) {46 while (true) {
src/ir.cpp+48-21
...@@ -721,17 +721,23 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in...@@ -721,17 +721,23 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in
721 return new_instruction;721 return new_instruction;
722}722}
723723
724static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, VariableTableEntry *var) {724static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
725 VariableTableEntry *var, bool is_const)
726{
725 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);727 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);
726 instruction->var = var;728 instruction->var = var;
729 instruction->is_const = is_const;
727730
728 ir_ref_var(var);731 ir_ref_var(var);
729732
730 return &instruction->base;733 return &instruction->base;
731}734}
732735
733static IrInstruction *ir_build_var_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, VariableTableEntry *var) {736static IrInstruction *ir_build_var_ptr_from(IrBuilder *irb, IrInstruction *old_instruction,
734 IrInstruction *new_instruction = ir_build_var_ptr(irb, old_instruction->scope, old_instruction->source_node, var);737 VariableTableEntry *var, bool is_const)
738{
739 IrInstruction *new_instruction = ir_build_var_ptr(irb, old_instruction->scope,
740 old_instruction->source_node, var, is_const);
735 ir_link_new_instruction(new_instruction, old_instruction);741 ir_link_new_instruction(new_instruction, old_instruction);
736 return new_instruction;742 return new_instruction;
737743
...@@ -3401,7 +3407,7 @@ static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, Tld...@@ -3401,7 +3407,7 @@ static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, Tld
3401 {3407 {
3402 TldVar *tld_var = (TldVar *)tld;3408 TldVar *tld_var = (TldVar *)tld;
3403 VariableTableEntry *var = tld_var->var;3409 VariableTableEntry *var = tld_var->var;
3404 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, source_node, var);3410 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, source_node, var, false);
3405 if (lval != LValPurposeNone)3411 if (lval != LValPurposeNone)
3406 return var_ptr;3412 return var_ptr;
3407 else3413 else
...@@ -3449,7 +3455,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3449,7 +3455,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
34493455
3450 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);3456 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);
3451 if (var) {3457 if (var) {
3452 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var);3458 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var, lval == LValPurposeAddressOfConst);
3453 if (lval != LValPurposeNone)3459 if (lval != LValPurposeNone)
3454 return var_ptr;3460 return var_ptr;
3455 else3461 else
...@@ -4309,7 +4315,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -4309,7 +4315,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
43094315
4310 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);4316 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);
4311 ir_build_var_decl(irb, child_scope, elem_node, elem_var, elem_var_type, undefined_value);4317 ir_build_var_decl(irb, child_scope, elem_node, elem_var, elem_var_type, undefined_value);
4312 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);4318 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var, false);
43134319
4314 AstNode *index_var_source_node;4320 AstNode *index_var_source_node;
4315 VariableTableEntry *index_var;4321 VariableTableEntry *index_var;
...@@ -4327,7 +4333,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -4327,7 +4333,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
4327 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);4333 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);
4328 IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1);4334 IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1);
4329 ir_build_var_decl(irb, child_scope, index_var_source_node, index_var, usize, zero);4335 ir_build_var_decl(irb, child_scope, index_var_source_node, index_var, usize, zero);
4330 IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var);4336 IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var, false);
43314337
43324338
4333 IrBasicBlock *cond_block = ir_build_basic_block(irb, child_scope, "ForCond");4339 IrBasicBlock *cond_block = ir_build_basic_block(irb, child_scope, "ForCond");
...@@ -4351,7 +4357,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -4351,7 +4357,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
4351 } else {4357 } else {
4352 elem_val = ir_build_load_ptr(irb, child_scope, node, elem_ptr);4358 elem_val = ir_build_load_ptr(irb, child_scope, node, elem_ptr);
4353 }4359 }
4354 ir_build_store_ptr(irb, child_scope, node, elem_var_ptr, elem_val);4360 ir_mark_gen(ir_build_store_ptr(irb, child_scope, node, elem_var_ptr, elem_val));
43554361
4356 LoopStackItem *loop_stack_item = irb->loop_stack.add_one();4362 LoopStackItem *loop_stack_item = irb->loop_stack.add_one();
4357 loop_stack_item->break_block = end_block;4363 loop_stack_item->break_block = end_block;
...@@ -4365,7 +4371,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -4365,7 +4371,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
43654371
4366 ir_set_cursor_at_end(irb, continue_block);4372 ir_set_cursor_at_end(irb, continue_block);
4367 IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false);4373 IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false);
4368 ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val);4374 ir_mark_gen(ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val));
4369 ir_build_br(irb, child_scope, node, cond_block, is_comptime);4375 ir_build_br(irb, child_scope, node, cond_block, is_comptime);
43704376
4371 ir_set_cursor_at_end(irb, end_block);4377 ir_set_cursor_at_end(irb, end_block);
...@@ -7545,9 +7551,15 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -7545,9 +7551,15 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
7545 size_t next_proto_i = 0;7551 size_t next_proto_i = 0;
75467552
7547 if (first_arg_ptr) {7553 if (first_arg_ptr) {
7548 IrInstruction *first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);7554 IrInstruction *first_arg;
7549 if (first_arg->value.type->id == TypeTableEntryIdInvalid)7555 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
7550 return ira->codegen->builtin_types.entry_invalid;7556 if (handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
7557 first_arg = first_arg_ptr;
7558 } else {
7559 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
7560 if (first_arg->value.type->id == TypeTableEntryIdInvalid)
7561 return ira->codegen->builtin_types.entry_invalid;
7562 }
75517563
7552 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope,7564 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope,
7553 &next_proto_i, generic_id, &fn_type_id, casted_args, impl_fn))7565 &next_proto_i, generic_id, &fn_type_id, casted_args, impl_fn))
...@@ -7612,9 +7624,15 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -7612,9 +7624,15 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
7612 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);7624 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);
7613 size_t next_arg_index = 0;7625 size_t next_arg_index = 0;
7614 if (first_arg_ptr) {7626 if (first_arg_ptr) {
7615 IrInstruction *first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);7627 IrInstruction *first_arg;
7616 if (first_arg->value.type->id == TypeTableEntryIdInvalid)7628 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
7617 return ira->codegen->builtin_types.entry_invalid;7629 if (handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
7630 first_arg = first_arg_ptr;
7631 } else {
7632 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
7633 if (first_arg->value.type->id == TypeTableEntryIdInvalid)
7634 return ira->codegen->builtin_types.entry_invalid;
7635 }
76187636
7619 TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;7637 TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
7620 if (param_type->id == TypeTableEntryIdInvalid)7638 if (param_type->id == TypeTableEntryIdInvalid)
...@@ -8090,7 +8108,9 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -8090,7 +8108,9 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
8090 return resolved_type;8108 return resolved_type;
8091}8109}
80928110
8093static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var) {8111static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
8112 VariableTableEntry *var, bool is_const_ptr)
8113{
8094 assert(var->value.type);8114 assert(var->value.type);
8095 if (var->value.type->id == TypeTableEntryIdInvalid)8115 if (var->value.type->id == TypeTableEntryIdInvalid)
8096 return var->value.type;8116 return var->value.type;
...@@ -8110,9 +8130,10 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc...@@ -8110,9 +8130,10 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc
81108130
8111 if (mem_slot && mem_slot->special != ConstValSpecialRuntime) {8131 if (mem_slot && mem_slot->special != ConstValSpecialRuntime) {
8112 ConstPtrSpecial ptr_special = is_comptime ? ConstPtrSpecialInline : ConstPtrSpecialNone;8132 ConstPtrSpecial ptr_special = is_comptime ? ConstPtrSpecialInline : ConstPtrSpecialNone;
8113 return ir_analyze_const_ptr(ira, instruction, mem_slot, var->value.type, false, ptr_special, var->src_is_const);8133 bool is_const = (var->value.type->id == TypeTableEntryIdMetaType) ? is_const_ptr : var->src_is_const;
8134 return ir_analyze_const_ptr(ira, instruction, mem_slot, var->value.type, false, ptr_special, is_const);
8114 } else {8135 } else {
8115 ir_build_var_ptr_from(&ira->new_irb, instruction, var);8136 ir_build_var_ptr_from(&ira->new_irb, instruction, var, false);
8116 type_ensure_zero_bits_known(ira->codegen, var->value.type);8137 type_ensure_zero_bits_known(ira->codegen, var->value.type);
8117 return get_pointer_to_type(ira->codegen, var->value.type, var->src_is_const);8138 return get_pointer_to_type(ira->codegen, var->value.type, var->src_is_const);
8118 }8139 }
...@@ -8120,7 +8141,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc...@@ -8120,7 +8141,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc
81208141
8121static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {8142static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {
8122 VariableTableEntry *var = var_ptr_instruction->var;8143 VariableTableEntry *var = var_ptr_instruction->var;
8123 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var);8144 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var, var_ptr_instruction->is_const);
8124}8145}
81258146
8126static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {8147static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
...@@ -8313,7 +8334,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source...@@ -8313,7 +8334,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
8313 {8334 {
8314 TldVar *tld_var = (TldVar *)tld;8335 TldVar *tld_var = (TldVar *)tld;
8315 VariableTableEntry *var = tld_var->var;8336 VariableTableEntry *var = tld_var->var;
8316 return ir_analyze_var_ptr(ira, source_instruction, var);8337 return ir_analyze_var_ptr(ira, source_instruction, var, false);
8317 }8338 }
8318 case TldIdFn:8339 case TldIdFn:
8319 {8340 {
...@@ -8549,6 +8570,12 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru...@@ -8549,6 +8570,12 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
8549 if (value->value.type->id == TypeTableEntryIdInvalid)8570 if (value->value.type->id == TypeTableEntryIdInvalid)
8550 return value->value.type;8571 return value->value.type;
85518572
8573 assert(ptr->value.type->id == TypeTableEntryIdPointer);
8574 if (ptr->value.type->data.pointer.is_const && !store_ptr_instruction->base.is_gen) {
8575 ir_add_error(ira, &store_ptr_instruction->base, buf_sprintf("cannot assign to constant"));
8576 return ira->codegen->builtin_types.entry_invalid;
8577 }
8578
8552 TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type;8579 TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type;
8553 IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type);8580 IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type);
8554 if (casted_value == ira->codegen->invalid_instruction)8581 if (casted_value == ira->codegen->invalid_instruction)
...@@ -8580,7 +8607,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru...@@ -8580,7 +8607,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
8580 IrInstructionVarPtr *var_ptr_inst = (IrInstructionVarPtr *)ptr;8607 IrInstructionVarPtr *var_ptr_inst = (IrInstructionVarPtr *)ptr;
8581 VariableTableEntry *var = var_ptr_inst->var;8608 VariableTableEntry *var = var_ptr_inst->var;
8582 new_ptr_inst = ir_build_var_ptr(&ira->new_irb, store_ptr_instruction->base.scope,8609 new_ptr_inst = ir_build_var_ptr(&ira->new_irb, store_ptr_instruction->base.scope,
8583 store_ptr_instruction->base.source_node, var);8610 store_ptr_instruction->base.source_node, var, false);
8584 assert(var->mem_slot_index != SIZE_MAX);8611 assert(var->mem_slot_index != SIZE_MAX);
8585 ConstExprValue *mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index];8612 ConstExprValue *mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index];
8586 mem_slot->special = ConstValSpecialRuntime;8613 mem_slot->special = ConstValSpecialRuntime;
std/cstr.zig+2-2
...@@ -39,7 +39,7 @@ pub const CBuf = struct {...@@ -39,7 +39,7 @@ pub const CBuf = struct {
3939
40 /// Must deinitialize with deinit.40 /// Must deinitialize with deinit.
41 pub fn initEmpty(allocator: &Allocator) -> %CBuf {41 pub fn initEmpty(allocator: &Allocator) -> %CBuf {
42 const self = CBuf {42 var self = CBuf {
43 .list = List(u8).init(allocator),43 .list = List(u8).init(allocator),
44 };44 };
45 %return self.resize(0);45 %return self.resize(0);
...@@ -48,7 +48,7 @@ pub const CBuf = struct {...@@ -48,7 +48,7 @@ pub const CBuf = struct {
4848
49 /// Must deinitialize with deinit.49 /// Must deinitialize with deinit.
50 pub fn initFromMem(allocator: &Allocator, m: []const u8) -> %CBuf {50 pub fn initFromMem(allocator: &Allocator, m: []const u8) -> %CBuf {
51 const self = CBuf {51 var self = CBuf {
52 .list = List(u8).init(allocator),52 .list = List(u8).init(allocator),
53 };53 };
54 %return self.resize(m.len);54 %return self.resize(m.len);
std/list.zig+1-1
...@@ -23,7 +23,7 @@ pub fn List(inline T: type) -> type{...@@ -23,7 +23,7 @@ pub fn List(inline T: type) -> type{
23 l.allocator.free(T, l.items);23 l.allocator.free(T, l.items);
24 }24 }
2525
26 pub fn toSlice(l: &Self) -> []T {26 pub fn toSlice(l: &const Self) -> []const T {
27 return l.items[0...l.len];27 return l.items[0...l.len];
28 }28 }
2929
test/cases/enum_with_members.zig+1-1
...@@ -6,7 +6,7 @@ const ET = enum {...@@ -6,7 +6,7 @@ const ET = enum {
6 SINT: i32,6 SINT: i32,
7 UINT: u32,7 UINT: u32,
88
9 pub fn print(a: &ET, buf: []u8) -> %usize {9 pub fn print(a: &const ET, buf: []u8) -> %usize {
10 return switch (*a) {10 return switch (*a) {
11 ET.SINT => |x| { io.bufPrintInt(i32, buf, x) },11 ET.SINT => |x| { io.bufPrintInt(i32, buf, x) },
12 ET.UINT => |x| { io.bufPrintInt(u32, buf, x) },12 ET.UINT => |x| { io.bufPrintInt(u32, buf, x) },
test/cases/misc.zig+7
...@@ -490,3 +490,10 @@ const test_pointer_to_void_return_type_x = void{};...@@ -490,3 +490,10 @@ const test_pointer_to_void_return_type_x = void{};
490fn testPointerToVoidReturnType2() -> &const void {490fn testPointerToVoidReturnType2() -> &const void {
491 return &test_pointer_to_void_return_type_x;491 return &test_pointer_to_void_return_type_x;
492}492}
493
494
495fn nonConstPtrToAliasedType() {
496 @setFnTest(this);
497 const int = i32;
498 assert(?&int == ?&i32);
499}
test/cases/struct.zig+2-2
...@@ -155,7 +155,7 @@ fn memberFunctions() {...@@ -155,7 +155,7 @@ fn memberFunctions() {
155}155}
156const MemberFnRand = struct {156const MemberFnRand = struct {
157 seed: u32,157 seed: u32,
158 pub fn getSeed(r: MemberFnRand) -> u32 {158 pub fn getSeed(r: &const MemberFnRand) -> u32 {
159 r.seed159 r.seed
160 }160 }
161};161};
...@@ -184,7 +184,7 @@ fn emptyStructMethodCall() {...@@ -184,7 +184,7 @@ fn emptyStructMethodCall() {
184 assert(es.method() == 1234);184 assert(es.method() == 1234);
185}185}
186const EmptyStruct = struct {186const EmptyStruct = struct {
187 fn method(es: EmptyStruct) -> i32 {187 fn method(es: &const EmptyStruct) -> i32 {
188 1234188 1234
189 }189 }
190};190};
test/run_tests.cpp+5-5
...@@ -548,7 +548,7 @@ const B = struct {...@@ -548,7 +548,7 @@ const B = struct {
548const C = struct {548const C = struct {
549 x: i32,549 x: i32,
550550
551 fn d(c: C) {551 fn d(c: &const C) {
552 %%io.stdout.printf("OK\n");552 %%io.stdout.printf("OK\n");
553 }553 }
554};554};
...@@ -577,13 +577,13 @@ const io = @import("std").io;...@@ -577,13 +577,13 @@ const io = @import("std").io;
577const Foo = struct {577const Foo = struct {
578 field1: Bar,578 field1: Bar,
579579
580 fn method(a: &Foo) -> bool { true }580 fn method(a: &const Foo) -> bool { true }
581};581};
582582
583const Bar = struct {583const Bar = struct {
584 field2: i32,584 field2: i32,
585585
586 fn method(b: &Bar) -> bool { true }586 fn method(b: &const Bar) -> bool { true }
587};587};
588588
589pub fn main(args: [][]u8) -> %void {589pub fn main(args: [][]u8) -> %void {
...@@ -787,14 +787,14 @@ fn f(a : unreachable) {}...@@ -787,14 +787,14 @@ fn f(a : unreachable) {}
787fn f() {787fn f() {
788 3 = 3;788 3 = 3;
789}789}
790 )SOURCE", 1, ".tmp_source.zig:3:5: error: invalid assignment target");790 )SOURCE", 1, ".tmp_source.zig:3:7: error: cannot assign to constant");
791791
792 add_compile_fail_case("assign to constant variable", R"SOURCE(792 add_compile_fail_case("assign to constant variable", R"SOURCE(
793fn f() {793fn f() {
794 const a = 3;794 const a = 3;
795 a = 4;795 a = 4;
796}796}
797 )SOURCE", 1, ".tmp_source.zig:4:5: error: cannot assign to constant");797 )SOURCE", 1, ".tmp_source.zig:4:7: error: cannot assign to constant");
798798
799 add_compile_fail_case("use of undeclared identifier", R"SOURCE(799 add_compile_fail_case("use of undeclared identifier", R"SOURCE(
800fn f() {800fn f() {