mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix issue with overloaded *= etc
This commit is contained in:
@@ -4,5 +4,5 @@ import std::io;
|
||||
fn void main()
|
||||
{
|
||||
const NUM = 4;
|
||||
NUM += 1; // #error: You cannot assign to a constant expression
|
||||
NUM += 1; // #error: You cannot assign to a constant
|
||||
}
|
||||
@@ -6,7 +6,7 @@ fn void tes2t(char* z, char[] out_data, char[] in_data) {
|
||||
z[0] = 2;
|
||||
z[0] += 1; // #error: 'out' parameters may not be read
|
||||
out_data[0] = 3;
|
||||
out_data[0] += 1; // #error: 'out' parameters may not be read
|
||||
out_data[0] *= 1; // #error: 'out' parameters may not be read
|
||||
out_data[0..3]; // #error: 'out' parameters may not be read
|
||||
out_data[0..3] = 23;
|
||||
}
|
||||
101
test/test_suite/methods/operator_assign_mutate.c3t
Normal file
101
test/test_suite/methods/operator_assign_mutate.c3t
Normal file
@@ -0,0 +1,101 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
import std::io, std::time, std::math, std::collections;
|
||||
|
||||
List(<long>) stones;
|
||||
|
||||
struct Foo
|
||||
{
|
||||
int[3] x;
|
||||
}
|
||||
|
||||
fn int Foo.get(self, usz i) @operator([]) => self.x[i];
|
||||
fn void Foo.set(&self, usz i, int z) @operator([]=) => self.x[i] = z;
|
||||
|
||||
fn void main() {
|
||||
stones.push(1);
|
||||
stones.push(100);
|
||||
stones[0] *= 3;
|
||||
stones[1] *= 2;
|
||||
stones[0] += 31;
|
||||
Foo z;
|
||||
z[1] += 5;
|
||||
z[1] *= 3;
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
define void @test.main() #0 {
|
||||
entry:
|
||||
%z = alloca %Foo, align 4
|
||||
%.anon = alloca ptr, align 8
|
||||
%.anon3 = alloca i32, align 4
|
||||
%.anon4 = alloca i32, align 4
|
||||
%coerce = alloca %Foo, align 8
|
||||
%.anon6 = alloca i32, align 4
|
||||
%.anon9 = alloca ptr, align 8
|
||||
%.anon10 = alloca i32, align 4
|
||||
%.anon11 = alloca i32, align 4
|
||||
%coerce13 = alloca %Foo, align 8
|
||||
%.anon17 = alloca i32, align 4
|
||||
call void @"std_collections_list$long$.List.push"(ptr @test.stones, i64 1) #2
|
||||
call void @"std_collections_list$long$.List.push"(ptr @test.stones, i64 100) #2
|
||||
%0 = call ptr @"std_collections_list$long$.List.get_ref"(ptr @test.stones, i64 0) #2
|
||||
%1 = load i64, ptr %0, align 8
|
||||
%mul = mul i64 %1, 3
|
||||
store i64 %mul, ptr %0, align 8
|
||||
%2 = call ptr @"std_collections_list$long$.List.get_ref"(ptr @test.stones, i64 1) #2
|
||||
%3 = load i64, ptr %2, align 8
|
||||
%mul1 = mul i64 %3, 2
|
||||
store i64 %mul1, ptr %2, align 8
|
||||
%4 = call ptr @"std_collections_list$long$.List.get_ref"(ptr @test.stones, i64 0) #2
|
||||
%5 = load i64, ptr %4, align 8
|
||||
%add = add i64 %5, 31
|
||||
store i64 %add, ptr %4, align 8
|
||||
store i32 0, ptr %z, align 4
|
||||
%ptradd = getelementptr inbounds i8, ptr %z, i64 4
|
||||
store i32 0, ptr %ptradd, align 4
|
||||
%ptradd2 = getelementptr inbounds i8, ptr %z, i64 8
|
||||
store i32 0, ptr %ptradd2, align 4
|
||||
store ptr %z, ptr %.anon, align 8
|
||||
store i32 1, ptr %.anon3, align 4
|
||||
%6 = load ptr, ptr %.anon, align 8
|
||||
%7 = load i32, ptr %.anon3, align 4
|
||||
%sext = sext i32 %7 to i64
|
||||
call void @llvm.memcpy.p0.p0.i32(ptr align 8 %coerce, ptr align 4 %6, i32 12, i1 false)
|
||||
%lo = load i64, ptr %coerce, align 8
|
||||
%ptradd5 = getelementptr inbounds i8, ptr %coerce, i64 8
|
||||
%hi = load i32, ptr %ptradd5, align 8
|
||||
%8 = call i32 @test.Foo.get(i64 %lo, i32 %hi, i64 %sext)
|
||||
store i32 %8, ptr %.anon4, align 4
|
||||
%9 = load i32, ptr %.anon4, align 4
|
||||
%add7 = add i32 %9, 5
|
||||
store i32 %add7, ptr %.anon4, align 4
|
||||
store i32 %add7, ptr %.anon6, align 4
|
||||
%10 = load i32, ptr %.anon3, align 4
|
||||
%sext8 = sext i32 %10 to i64
|
||||
%11 = load ptr, ptr %.anon, align 8
|
||||
%12 = load i32, ptr %.anon4, align 4
|
||||
call void @test.Foo.set(ptr %11, i64 %sext8, i32 %12)
|
||||
store ptr %z, ptr %.anon9, align 8
|
||||
store i32 1, ptr %.anon10, align 4
|
||||
%13 = load ptr, ptr %.anon9, align 8
|
||||
%14 = load i32, ptr %.anon10, align 4
|
||||
%sext12 = sext i32 %14 to i64
|
||||
call void @llvm.memcpy.p0.p0.i32(ptr align 8 %coerce13, ptr align 4 %13, i32 12, i1 false)
|
||||
%lo14 = load i64, ptr %coerce13, align 8
|
||||
%ptradd15 = getelementptr inbounds i8, ptr %coerce13, i64 8
|
||||
%hi16 = load i32, ptr %ptradd15, align 8
|
||||
%15 = call i32 @test.Foo.get(i64 %lo14, i32 %hi16, i64 %sext12)
|
||||
store i32 %15, ptr %.anon11, align 4
|
||||
%16 = load i32, ptr %.anon11, align 4
|
||||
%mul18 = mul i32 %16, 3
|
||||
store i32 %mul18, ptr %.anon11, align 4
|
||||
store i32 %mul18, ptr %.anon17, align 4
|
||||
%17 = load i32, ptr %.anon10, align 4
|
||||
%sext19 = sext i32 %17 to i64
|
||||
%18 = load ptr, ptr %.anon9, align 8
|
||||
%19 = load i32, ptr %.anon11, align 4
|
||||
call void @test.Foo.set(ptr %18, i64 %sext19, i32 %19)
|
||||
ret void
|
||||
}
|
||||
Reference in New Issue
Block a user