yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
0e6c5c518
master
1//TEST:SIMPLE(filecheck=CHECK): 2 3// Test to catch compilation time errors with return values in constructors within an ordinary struct. 4// A constructor from the callsite's point of view is a function that returns the struct type. 5// A constructor from the inside the body is treated as a function that modifies `this` and not return. 6 7// In the following test-cases where the constructor either returns an expr or no value, 8// within a condition for early exit or not, it automatically gets resolved as 9// this = t; 10// return *this; or return; 11 12struct S 13{ 14 float v; 15 __init() { v = 0; } 16} 17 18struct S1a : S 19{ 20 __init() 21 { 22 this.v = 5; 23 // CHECK-NOT: ([[# @LINE+1]]): error 24 return this; 25 } 26} 27 28struct S1b : S 29{ 30 __init(float u) 31 { 32 if (u != 0) 33 { 34 this.v = u; 35 // CHECK-NOT: ([[# @LINE+1]]): error 36 return this; 37 } 38 // CHECK-NOT: ([[# @LINE+1]]): error 39 return; 40 } 41} 42 43struct S2a : S 44{ 45 __init() 46 { 47 S2a t; 48 t.v = 5; 49 // CHECK-NOT: ([[# @LINE+1]]): error 50 return; 51 } 52} 53 54struct S2b : S 55{ 56 __init(float u) 57 { 58 if (u != 0) 59 { 60 S2b t; 61 t.v = u; 62 // CHECK-NOT: ([[# @LINE+1]]): error 63 return; 64 } 65 // CHECK-NOT: ([[# @LINE+1]]): error 66 return; 67 } 68} 69 70struct S3a : S 71{ 72 __init() 73 { 74 S3a t; 75 t.v = 5; 76 // CHECK-NOT: ([[# @LINE+1]]): error 77 return t; 78 } 79} 80 81struct S3b : S 82{ 83 __init(float u) 84 { 85 if (u != 0) 86 { 87 S3b t; 88 t.v = u; 89 // CHECK-NOT: ([[# @LINE+1]]): error 90 return t; 91 } 92 // CHECK-NOT: ([[# @LINE+1]]): error 93 return; 94 } 95} 96 97void main() 98{ 99 S1a S1a; 100 S2a S2a; 101 S3a S3a; 102 S1b S1b = S1b(0); 103 S2b S2b = S2b(0); 104 S3b S3b = S3b(0); 105}