1group valid "Valid scoping and name redeclaration cases" 2 3 case local_variable_hides_global_variable 4 version 310 es 5 values 6 { 7 input int in0 = [ 1 | 2 | 3 ]; 8 output int out0 = [ 1 | 2 | 3 ]; 9 } 10 11 both "" 12 #version 310 es 13 precision highp float; 14 precision highp int; 15 ${DECLARATIONS} 16 17 int a = -1; 18 19 void main() 20 { 21 ${SETUP} 22 int a = in0; 23 24 out0 = a; 25 ${OUTPUT} 26 } 27 "" 28 end 29 30 case block_variable_hides_local_variable 31 version 310 es 32 values 33 { 34 input int in0 = [ 1 | 2 | 3 ]; 35 output int out0 = [ 1 | 2 | 3 ]; 36 } 37 38 both "" 39 #version 310 es 40 precision highp float; 41 precision highp int; 42 ${DECLARATIONS} 43 void main() 44 { 45 ${SETUP} 46 int a = in0; 47 { 48 int a = -1; 49 } 50 out0 = a; 51 ${OUTPUT} 52 } 53 "" 54 end 55 56 case block_variable_hides_global_variable 57 version 310 es 58 values 59 { 60 input int in0 = [ 1 | 2 | 3 ]; 61 output int out0 = [ 1 | 2 | 3 ]; 62 } 63 64 both "" 65 #version 310 es 66 precision highp float; 67 precision highp int; 68 ${DECLARATIONS} 69 70 int a = -1; 71 72 void main() 73 { 74 ${SETUP} 75 { 76 int a = in0; 77 78 out0 = a; 79 } 80 ${OUTPUT} 81 } 82 "" 83 end 84 85 case for_init_statement_variable_hides_local_variable 86 version 310 es 87 values 88 { 89 input int in0 = [ 1 | 2 | 3 ]; 90 output int out0 = [ 1 | 2 | 3 ]; 91 } 92 93 both "" 94 #version 310 es 95 precision highp float; 96 precision highp int; 97 ${DECLARATIONS} 98 void main() 99 { 100 ${SETUP} 101 int a = in0; 102 for (int a = 0; a < 10; a++) 103 { 104 } 105 out0 = a; 106 ${OUTPUT} 107 } 108 "" 109 end 110 111 case while_condition_variable_hides_local_variable 112 version 310 es 113 values 114 { 115 input int in0 = [ 1 | 2 | 3 ]; 116 output int out0 = [ 1 | 2 | 3 ]; 117 } 118 119 both "" 120 #version 310 es 121 precision highp float; 122 precision highp int; 123 ${DECLARATIONS} 124 void main() 125 { 126 ${SETUP} 127 int a = in0; 128 int i = 0; 129 while (bool a = (i < 1)) 130 { 131 i++; 132 } 133 out0 = a; 134 ${OUTPUT} 135 } 136 "" 137 end 138 139 case for_init_statement_variable_hides_global_variable 140 version 310 es 141 values 142 { 143 input int in0 = [ 1 | 2 | 3 ]; 144 output int out0 = [ 1 | 2 | 3 ]; 145 } 146 147 both "" 148 #version 310 es 149 precision highp float; 150 precision highp int; 151 ${DECLARATIONS} 152 153 int a = 5; 154 155 void main() 156 { 157 ${SETUP} 158 for (int a = 0; a < 10; a++) 159 { 160 } 161 out0 = in0 + a - 5; 162 ${OUTPUT} 163 } 164 "" 165 end 166 167 case while_condition_variable_hides_global_variable 168 version 310 es 169 values 170 { 171 input int in0 = [ 1 | 2 | 3 ]; 172 output int out0 = [ 1 | 2 | 3 ]; 173 } 174 175 both "" 176 #version 310 es 177 precision highp float; 178 precision highp int; 179 ${DECLARATIONS} 180 181 int a = 5; 182 183 void main() 184 { 185 ${SETUP} 186 int i = 0; 187 while (bool a = (i < 1)) 188 { 189 i++; 190 } 191 out0 = in0 + a - 5; 192 ${OUTPUT} 193 } 194 "" 195 end 196 197 case variable_in_if_hides_global_variable 198 version 310 es 199 values 200 { 201 input int in0 = [ 1 | 2 | 3 ]; 202 output int out0 = [ 1 | 2 | 3 ]; 203 } 204 205 both "" 206 #version 310 es 207 precision highp float; 208 precision highp int; 209 ${DECLARATIONS} 210 211 int a = 1; 212 213 void main() 214 { 215 ${SETUP} 216 if (true) 217 int a = 42; 218 out0 = a*in0; 219 ${OUTPUT} 220 } 221 "" 222 end 223 224 case variable_from_outer_scope_visible_in_initializer 225 version 310 es 226 values 227 { 228 input int in0 = [ 1 | 2 | 3 ]; 229 output int out0 = [ 1 | 2 | 3 ]; 230 } 231 232 both "" 233 #version 310 es 234 precision highp float; 235 precision highp int; 236 ${DECLARATIONS} 237 void main() 238 { 239 ${SETUP} 240 int a = in0; 241 { 242 int a = a+5, b = a-5; 243 out0 = b; 244 a = 42; 245 } 246 out0 = out0 + a - in0; 247 ${OUTPUT} 248 } 249 "" 250 end 251 252 case local_int_variable_hides_struct_type 253 version 310 es 254 values 255 { 256 input int in0 = [ 1 | 2 | 3 ]; 257 output int out0 = [ 1 | 2 | 3 ]; 258 } 259 260 both "" 261 #version 310 es 262 precision highp float; 263 precision highp int; 264 ${DECLARATIONS} 265 266 struct S { int val; }; 267 268 void main() 269 { 270 ${SETUP} 271 int S = S(in0).val; 272 out0 = S; 273 ${OUTPUT} 274 } 275 "" 276 end 277 278 case local_struct_variable_hides_struct_type 279 version 310 es 280 values 281 { 282 input int in0 = [ 1 | 2 | 3 ]; 283 output int out0 = [ 1 | 2 | 3 ]; 284 } 285 286 both "" 287 #version 310 es 288 precision highp float; 289 precision highp int; 290 ${DECLARATIONS} 291 292 struct S { int val; }; 293 294 void main() 295 { 296 ${SETUP} 297 S S = S(in0); 298 out0 = S.val; 299 ${OUTPUT} 300 } 301 "" 302 end 303 304 case local_variable_hides_function 305 version 310 es 306 values 307 { 308 input int in0 = [ 1 | 2 | 3 ]; 309 output int out0 = [ 1 | 2 | 3 ]; 310 } 311 312 both "" 313 #version 310 es 314 precision highp float; 315 precision highp int; 316 ${DECLARATIONS} 317 318 int foo (int x) { return x; } 319 320 void main() 321 { 322 ${SETUP} 323 int foo = in0; 324 out0 = foo; 325 ${OUTPUT} 326 } 327 "" 328 end 329 330 case function_parameter_hides_global_variable 331 version 310 es 332 values 333 { 334 input int in0 = [ 1 | 2 | 3 ]; 335 output int out0 = [ 1 | 2 | 3 ]; 336 } 337 338 both "" 339 #version 310 es 340 precision highp float; 341 precision highp int; 342 ${DECLARATIONS} 343 344 int a = -1; 345 346 int func (int a) { return a; } 347 348 void main() 349 { 350 ${SETUP} 351 out0 = func(in0); 352 ${OUTPUT} 353 } 354 "" 355 end 356 357 case function_parameter_hides_struct_type 358 version 310 es 359 values 360 { 361 input int in0 = [ 1 | 2 | 3 ]; 362 output int out0 = [ 1 | 2 | 3 ]; 363 } 364 365 both "" 366 #version 310 es 367 precision highp float; 368 precision highp int; 369 ${DECLARATIONS} 370 371 struct S { int x; }; 372 373 int func (int S) { return S; } 374 375 void main() 376 { 377 ${SETUP} 378 out0 = func(in0); 379 ${OUTPUT} 380 } 381 "" 382 end 383 384 case function_parameter_hides_function 385 version 310 es 386 values 387 { 388 input int in0 = [ 1 | 2 | 3 ]; 389 output int out0 = [ 1 | 2 | 3 ]; 390 } 391 392 both "" 393 #version 310 es 394 precision highp float; 395 precision highp int; 396 ${DECLARATIONS} 397 398 int func (int func) { return func; } 399 400 void main() 401 { 402 ${SETUP} 403 out0 = func(in0); 404 ${OUTPUT} 405 } 406 "" 407 end 408 409 case local_variable_in_inner_scope_hides_function_parameter 410 version 310 es 411 values 412 { 413 input int in0 = [ 1 | 2 | 3 ]; 414 output int out0 = [ 1 | 2 | 3 ]; 415 } 416 417 both "" 418 #version 310 es 419 precision highp float; 420 precision highp int; 421 ${DECLARATIONS} 422 int func (int inp, int x) { { int x = 5; return inp + x - 5; } } 423 424 void main() 425 { 426 ${SETUP} 427 out0 = func(in0, 42); 428 ${OUTPUT} 429 } 430 "" 431 end 432 433 case redeclare_function 434 version 310 es 435 values 436 { 437 input int in0 = [ 1 | 2 | 3 ]; 438 output int out0 = [ 1 | 2 | 3 ]; 439 } 440 441 both "" 442 #version 310 es 443 precision highp float; 444 precision highp int; 445 ${DECLARATIONS} 446 447 int func (int x); 448 int func (int); 449 int func (int inp) { return inp; } 450 451 void main() 452 { 453 ${SETUP} 454 out0 = func(in0); 455 ${OUTPUT} 456 } 457 "" 458 end 459 460end 461