1group valid "Valid scoping and name redeclaration cases"
2
3	case local_variable_hides_global_variable
4		version 300 es
5		values
6		{
7			input int in0 = [ 1 | 2 | 3 ];
8			output int out0 = [ 1 | 2 | 3 ];
9		}
10
11		both ""
12			#version 300 es
13			precision mediump float;
14			${DECLARATIONS}
15
16			int a = -1;
17
18			void main()
19			{
20				${SETUP}
21				int a = in0;
22
23				out0 = a;
24				${OUTPUT}
25			}
26		""
27	end
28
29	case block_variable_hides_local_variable
30		version 300 es
31		values
32		{
33			input int in0 = [ 1 | 2 | 3 ];
34			output int out0 = [ 1 | 2 | 3 ];
35		}
36
37		both ""
38			#version 300 es
39			precision mediump float;
40			${DECLARATIONS}
41			void main()
42			{
43				${SETUP}
44				int a = in0;
45				{
46					int a = -1;
47				}
48				out0 = a;
49				${OUTPUT}
50			}
51		""
52	end
53
54	case block_variable_hides_global_variable
55		version 300 es
56		values
57		{
58			input int in0 = [ 1 | 2 | 3 ];
59			output int out0 = [ 1 | 2 | 3 ];
60		}
61
62		both ""
63			#version 300 es
64			precision mediump float;
65			${DECLARATIONS}
66
67			int a = -1;
68
69			void main()
70			{
71				${SETUP}
72				{
73					int a = in0;
74
75					out0 = a;
76				}
77				${OUTPUT}
78			}
79		""
80	end
81
82	case for_init_statement_variable_hides_local_variable
83		version 300 es
84		values
85		{
86			input int in0 = [ 1 | 2 | 3 ];
87			output int out0 = [ 1 | 2 | 3 ];
88		}
89
90		both ""
91			#version 300 es
92			precision mediump float;
93			${DECLARATIONS}
94			void main()
95			{
96				${SETUP}
97				int a = in0;
98				for (int a = 0; a < 10; a++)
99				{
100				}
101				out0 = a;
102				${OUTPUT}
103			}
104		""
105	end
106
107	case while_condition_variable_hides_local_variable
108		version 300 es
109		values
110		{
111			input int in0 = [ 1 | 2 | 3 ];
112			output int out0 = [ 1 | 2 | 3 ];
113		}
114
115		both ""
116			#version 300 es
117			precision mediump float;
118			${DECLARATIONS}
119			void main()
120			{
121				${SETUP}
122				int a = in0;
123				int i = 0;
124				while (bool a = (i < 1))
125				{
126					i++;
127				}
128				out0 = a;
129				${OUTPUT}
130			}
131		""
132	end
133
134	case for_init_statement_variable_hides_global_variable
135		version 300 es
136		values
137		{
138			input int in0 = [ 1 | 2 | 3 ];
139			output int out0 = [ 1 | 2 | 3 ];
140		}
141
142		both ""
143			#version 300 es
144			precision mediump float;
145			${DECLARATIONS}
146
147			int a = 5;
148
149			void main()
150			{
151				${SETUP}
152				for (int a = 0; a < 10; a++)
153				{
154				}
155				out0 = in0 + a - 5;
156				${OUTPUT}
157			}
158		""
159	end
160
161	case while_condition_variable_hides_global_variable
162		version 300 es
163		values
164		{
165			input int in0 = [ 1 | 2 | 3 ];
166			output int out0 = [ 1 | 2 | 3 ];
167		}
168
169		both ""
170			#version 300 es
171			precision mediump float;
172			${DECLARATIONS}
173
174			int a = 5;
175
176			void main()
177			{
178				${SETUP}
179				int i = 0;
180				while (bool a = (i < 1))
181				{
182					i++;
183				}
184				out0 = in0 + a - 5;
185				${OUTPUT}
186			}
187		""
188	end
189
190	case variable_in_if_hides_global_variable
191		version 300 es
192		values
193		{
194			input int in0 = [ 1 | 2 | 3 ];
195			output int out0 = [ 1 | 2 | 3 ];
196		}
197
198		both ""
199			#version 300 es
200			precision mediump float;
201			${DECLARATIONS}
202
203			int a = 1;
204
205			void main()
206			{
207				${SETUP}
208				if (true)
209					int a = 42;
210				out0 = a*in0;
211				${OUTPUT}
212			}
213		""
214	end
215
216	case variable_from_outer_scope_visible_in_initializer
217		version 300 es
218		values
219		{
220			input int in0 = [ 1 | 2 | 3 ];
221			output int out0 = [ 1 | 2 | 3 ];
222		}
223
224		both ""
225			#version 300 es
226			precision mediump float;
227			${DECLARATIONS}
228			void main()
229			{
230				${SETUP}
231				int a = in0;
232				{
233					int a = a+5, b = a-5;
234					out0 = b;
235					a = 42;
236				}
237				out0 = out0 + a - in0;
238				${OUTPUT}
239			}
240		""
241	end
242
243	case local_int_variable_hides_struct_type
244		version 300 es
245		values
246		{
247			input int in0 = [ 1 | 2 | 3 ];
248			output int out0 = [ 1 | 2 | 3 ];
249		}
250
251		both ""
252			#version 300 es
253			precision mediump float;
254			${DECLARATIONS}
255
256			struct S { int val; };
257
258			void main()
259			{
260				${SETUP}
261				int S = S(in0).val;
262				out0 = S;
263				${OUTPUT}
264			}
265		""
266	end
267
268	case local_struct_variable_hides_struct_type
269		version 300 es
270		values
271		{
272			input int in0 = [ 1 | 2 | 3 ];
273			output int out0 = [ 1 | 2 | 3 ];
274		}
275
276		both ""
277			#version 300 es
278			precision mediump float;
279			${DECLARATIONS}
280
281			struct S { int val; };
282
283			void main()
284			{
285				${SETUP}
286				S S = S(in0);
287				out0 = S.val;
288				${OUTPUT}
289			}
290		""
291	end
292
293	case local_variable_hides_function
294		version 300 es
295		values
296		{
297			input int in0 = [ 1 | 2 | 3 ];
298			output int out0 = [ 1 | 2 | 3 ];
299		}
300
301		both ""
302			#version 300 es
303			precision mediump float;
304			${DECLARATIONS}
305
306			int foo (int x) { return x; }
307
308			void main()
309			{
310				${SETUP}
311				int foo = in0;
312				out0 = foo;
313				${OUTPUT}
314			}
315		""
316	end
317
318	case function_parameter_hides_global_variable
319		version 300 es
320		values
321		{
322			input int in0 = [ 1 | 2 | 3 ];
323			output int out0 = [ 1 | 2 | 3 ];
324		}
325
326		both ""
327			#version 300 es
328			precision mediump float;
329			${DECLARATIONS}
330
331			int a = -1;
332
333			int func (int a) { return a; }
334
335			void main()
336			{
337				${SETUP}
338				out0 = func(in0);
339				${OUTPUT}
340			}
341		""
342	end
343
344	case function_parameter_hides_struct_type
345		version 300 es
346		values
347		{
348			input int in0 = [ 1 | 2 | 3 ];
349			output int out0 = [ 1 | 2 | 3 ];
350		}
351
352		both ""
353			#version 300 es
354			precision mediump float;
355			${DECLARATIONS}
356
357			struct S { int x; };
358
359			int func (int S) { return S; }
360
361			void main()
362			{
363				${SETUP}
364				out0 = func(in0);
365				${OUTPUT}
366			}
367		""
368	end
369
370	case function_parameter_hides_function
371		version 300 es
372		values
373		{
374			input int in0 = [ 1 | 2 | 3 ];
375			output int out0 = [ 1 | 2 | 3 ];
376		}
377
378		both ""
379			#version 300 es
380			precision mediump float;
381			${DECLARATIONS}
382
383			int func (int func) { return func; }
384
385			void main()
386			{
387				${SETUP}
388				out0 = func(in0);
389				${OUTPUT}
390			}
391		""
392	end
393
394	case local_variable_in_inner_scope_hides_function_parameter
395		version 300 es
396		values
397		{
398			input int in0 = [ 1 | 2 | 3 ];
399			output int out0 = [ 1 | 2 | 3 ];
400		}
401
402		both ""
403			#version 300 es
404			precision mediump float;
405			${DECLARATIONS}
406			int func (int inp, int x) { { int x = 5; return inp + x - 5; } }
407
408			void main()
409			{
410				${SETUP}
411				out0 = func(in0, 42);
412				${OUTPUT}
413			}
414		""
415	end
416
417	case redeclare_function
418		version 300 es
419		values
420		{
421			input int in0 = [ 1 | 2 | 3 ];
422			output int out0 = [ 1 | 2 | 3 ];
423		}
424
425		both ""
426			#version 300 es
427			precision mediump float;
428			${DECLARATIONS}
429
430			int func (int x);
431			int func (int);
432			int func (int inp) { return inp; }
433
434			void main()
435			{
436				${SETUP}
437				out0 = func(in0);
438				${OUTPUT}
439			}
440		""
441	end
442
443end
444
445group invalid "Invalid scoping behavior"
446
447	case redeclare_global_variable
448		version 300 es
449		expect compile_fail
450		both ""
451			#version 300 es
452			precision mediump float;
453			${DECLARATIONS}
454
455			int a;
456			float a;
457
458			void main()
459			{
460				a = 1.0;
461				${POSITION_FRAG_COLOR} = vec4(a);
462			}
463		""
464	end
465
466	case redeclare_local_variable
467		version 300 es
468		expect compile_fail
469		both ""
470			#version 300 es
471			precision mediump float;
472			${DECLARATIONS}
473
474			void main()
475			{
476				int a;
477				float a;
478				a = 1.0;
479				${POSITION_FRAG_COLOR} = vec4(a);
480			}
481		""
482	end
483
484	case redeclare_for_init_statement_variable
485		version 300 es
486		expect compile_fail
487		both ""
488			#version 300 es
489			precision mediump float;
490			${DECLARATIONS}
491
492			void main()
493			{
494				for (int i = 0; i < 10; i++)
495				{
496					int i = 11;
497				}
498				${POSITION_FRAG_COLOR} = vec4(0.0);
499			}
500		""
501	end
502
503	case redeclare_for_condition_variable
504		version 300 es
505		expect compile_fail
506		both ""
507			#version 300 es
508			precision mediump float;
509			${DECLARATIONS}
510
511			void main()
512			{
513				for (int i = 0; int a = (i < 10); i++)
514				{
515					int a = 0;
516				}
517				${POSITION_FRAG_COLOR} = vec4(0.0);
518			}
519		""
520	end
521
522	case redeclare_for_init_statement_variable_in_for_condition
523		version 300 es
524		expect compile_fail
525		both ""
526			#version 300 es
527			precision mediump float;
528			${DECLARATIONS}
529
530			void main()
531			{
532				float a;
533				for (int i = 0; int i = (i < 10); i++)
534				{
535					a = sin(i);
536				}
537				${POSITION_FRAG_COLOR} = vec4(a);
538			}
539		""
540	end
541
542	case redeclare_while_condition_variable
543		version 300 es
544		expect compile_fail
545		both ""
546			#version 300 es
547			precision mediump float;
548			${DECLARATIONS}
549
550			void main()
551			{
552				int a = 0;
553				while (int i = (a < 5))
554				{
555					int i = 11;
556					a += i;
557				}
558				${POSITION_FRAG_COLOR} = vec4(0.0);
559			}
560		""
561	end
562
563	case redefine_function
564		version 300 es
565		expect compile_fail
566		both ""
567			#version 300 es
568			precision mediump float;
569			${DECLARATIONS}
570
571			float func(float x);
572
573			float func(float x) { return x + 1.0; }
574			float func(float x) { return x + 2.0; }
575
576			void main()
577			{
578				${POSITION_FRAG_COLOR} = vec4(func(1.0));
579			}
580		""
581	end
582
583	case redeclare_builtin
584		version 300 es
585		expect compile_fail
586		both ""
587			#version 300 es
588			precision mediump float;
589			${DECLARATIONS}
590
591			float sin(float x);
592
593			void main()
594			{
595				${POSITION_FRAG_COLOR} = vec4(sin(1.0));
596			}
597		""
598	end
599
600	case redefine_builtin
601		version 300 es
602		expect compile_fail
603		both ""
604			#version 300 es
605			precision mediump float;
606			${DECLARATIONS}
607
608			float sin(float x) { return x + 1.0; }
609
610			void main()
611			{
612				${POSITION_FRAG_COLOR} = vec4(sin(1.0));
613			}
614		""
615	end
616
617	case conflict_function_struct
618		version 300 es
619		expect compile_fail
620		both ""
621			#version 300 es
622			precision mediump float;
623			${DECLARATIONS}
624
625			void f(int x);
626			struct f { int x; };
627
628			void main()
629			{
630				${POSITION_FRAG_COLOR} = vec4(1);
631			}
632		""
633	end
634
635	case conflict_function_variable
636		version 300 es
637		expect compile_fail
638		both ""
639			#version 300 es
640			precision mediump float;
641			${DECLARATIONS}
642
643			void f(int x);
644			float f;
645
646			void main()
647			{
648				f = 1.0;
649				${POSITION_FRAG_COLOR} = vec4(f);
650			}
651		""
652	end
653
654	case use_global_variable_before_declaration
655		version 300 es
656		expect compile_fail
657		both ""
658			#version 300 es
659			precision mediump float;
660			${DECLARATIONS}
661
662			void func()
663			{
664				a = 2.0;
665			}
666
667			float a;
668
669			void main()
670			{
671				func();
672				${POSITION_FRAG_COLOR} = vec4(a);
673			}
674		""
675	end
676
677	case use_local_variable_before_declaration
678		version 300 es
679		expect compile_fail
680		both ""
681			#version 300 es
682			precision mediump float;
683			${DECLARATIONS}
684
685			void main()
686			{
687				float a = 1.0;
688				a = b;
689				float b = 2.0;
690
691				${POSITION_FRAG_COLOR} = vec4(a);
692			}
693		""
694	end
695
696	case use_struct_type_before_declaration
697		version 300 es
698		expect compile_fail
699		both ""
700			#version 300 es
701			precision mediump float;
702			${DECLARATIONS}
703
704			float func (float x) { return S(x).val; }
705			struct S { float val; };
706
707			void main()
708			{
709				${POSITION_FRAG_COLOR} = vec4(func(1.0));
710			}
711		""
712	end
713
714	case use_function_before_declaration
715		version 300 es
716		expect compile_fail
717		both ""
718			#version 300 es
719			precision mediump float;
720			${DECLARATIONS}
721
722			float func (float x) { return bar(x); }
723			float bar (float x) { return x; }
724
725			void main()
726			{
727				${POSITION_FRAG_COLOR} = vec4(func(1.0));
728			}
729		""
730	end
731
732	case use_variable_from_block_in_outer_scope
733		version 300 es
734		expect compile_fail
735		both ""
736			#version 300 es
737			precision mediump float;
738			${DECLARATIONS}
739
740			void main()
741			{
742				{
743					float a = 1.0;
744				}
745				${POSITION_FRAG_COLOR} = vec4(a);
746			}
747		""
748	end
749
750	case use_variable_from_if_in_outer_scope
751		version 300 es
752		expect compile_fail
753		both ""
754			#version 300 es
755			precision mediump float;
756			${DECLARATIONS}
757
758			void main()
759			{
760				if (true)
761					float a = 1.0;
762				${POSITION_FRAG_COLOR} = vec4(a);
763			}
764		""
765	end
766
767	case use_variable_from_else_in_outer_scope
768		version 300 es
769		expect compile_fail
770		both ""
771			#version 300 es
772			precision mediump float;
773			${DECLARATIONS}
774
775			void main()
776			{
777				if (false)
778					float a = 1.0;
779				else
780					float b = 2.0;
781				${POSITION_FRAG_COLOR} = vec4(b);
782			}
783		""
784	end
785
786	case use_variable_from_if_in_else
787		version 300 es
788		expect compile_fail
789		both ""
790			#version 300 es
791			precision mediump float;
792			${DECLARATIONS}
793
794			void main()
795			{
796				float a = 1.0;
797				if (true)
798				{
799					float b = 2.0;
800				}
801				else
802				{
803					a = b;
804				}
805				${POSITION_FRAG_COLOR} = vec4(a);
806			}
807		""
808	end
809
810	case use_variable_from_for_init_statement_in_outer_scope
811		version 300 es
812		expect compile_fail
813		both ""
814			#version 300 es
815			precision mediump float;
816			${DECLARATIONS}
817
818			void main()
819			{
820				float x = 0.0;
821				for (int i = 0; i < 10; i++)
822				{
823					x += sin(i);
824				}
825				${POSITION_FRAG_COLOR} = vec4(float(i));
826			}
827		""
828	end
829
830	case use_variable_from_while_condition_in_outer_scope
831		version 300 es
832		expect compile_fail
833		both ""
834			#version 300 es
835			precision mediump float;
836			${DECLARATIONS}
837
838			void main()
839			{
840				int a = 1;
841				while (bool b = (a == 1))
842				{
843					a++;
844				}
845				${POSITION_FRAG_COLOR} = vec4(float(b));
846			}
847		""
848	end
849
850	case use_parameter_names_from_function_declaration
851		version 300 es
852		expect compile_fail
853		both ""
854			#version 300 es
855			precision mediump float;
856			${DECLARATIONS}
857
858			float func(float a, float b);
859
860			float func(float x, float y) { return a+b; }
861
862			void main()
863			{
864				${POSITION_FRAG_COLOR} = vec4(func(1.0, 2.0));
865			}
866		""
867	end
868
869	case variable_not_visible_in_own_initializer
870		version 300 es
871		expect compile_fail
872		both ""
873			#version 300 es
874			precision mediump float;
875			${DECLARATIONS}
876
877			void main()
878			{
879				float x = x;
880				${POSITION_FRAG_COLOR} = vec4(x);
881			}
882		""
883	end
884
885	case local_variable_hides_function_parameter
886		version 300 es
887		expect compile_fail
888		both ""
889			#version 300 es
890			precision mediump float;
891			${DECLARATIONS}
892			float func (float inp, float x) { int x = 5.0; return inp + x - 5.0; }
893
894			void main()
895			{
896				${POSITION_FRAG_COLOR} = vec4(func(1.0, 2.0));
897			}
898		""
899	end
900
901end # invalid
902