1group valid "Valid scoping and name redeclaration cases"
2
3	case local_variable_hides_global_variable
4		version 100 es
5		values
6		{
7			input int in0 = [ 1 | 2 | 3 ];
8			output int out0 = [ 1 | 2 | 3 ];
9		}
10
11		both ""
12			#version 100
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 100 es
31		values
32		{
33			input int in0 = [ 1 | 2 | 3 ];
34			output int out0 = [ 1 | 2 | 3 ];
35		}
36
37		both ""
38			#version 100
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 100 es
56		values
57		{
58			input int in0 = [ 1 | 2 | 3 ];
59			output int out0 = [ 1 | 2 | 3 ];
60		}
61
62		both ""
63			#version 100
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 100 es
84		values
85		{
86			input int in0 = [ 1 | 2 | 3 ];
87			output int out0 = [ 1 | 2 | 3 ];
88		}
89
90		both ""
91			#version 100
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 100 es
109		values
110		{
111			input int in0 = [ 1 | 2 | 3 ];
112			output int out0 = [ 1 | 2 | 3 ];
113		}
114
115		both ""
116			#version 100
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 100 es
136		values
137		{
138			input int in0 = [ 1 | 2 | 3 ];
139			output int out0 = [ 1 | 2 | 3 ];
140		}
141
142		both ""
143			#version 100
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 100 es
163		values
164		{
165			input int in0 = [ 1 | 2 | 3 ];
166			output int out0 = [ 1 | 2 | 3 ];
167		}
168
169		both ""
170			#version 100
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 100 es
192		values
193		{
194			input int in0 = [ 1 | 2 | 3 ];
195			output int out0 = [ 1 | 2 | 3 ];
196		}
197
198		both ""
199			#version 100
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 100 es
218		values
219		{
220			input int in0 = [ 1 | 2 | 3 ];
221			output int out0 = [ 1 | 2 | 3 ];
222		}
223
224		both ""
225			#version 100
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 100 es
245		values
246		{
247			input int in0 = [ 1 | 2 | 3 ];
248			output int out0 = [ 1 | 2 | 3 ];
249		}
250
251		both ""
252			#version 100
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 100 es
270		values
271		{
272			input int in0 = [ 1 | 2 | 3 ];
273			output int out0 = [ 1 | 2 | 3 ];
274		}
275
276		both ""
277			#version 100
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 100 es
295		values
296		{
297			input int in0 = [ 1 | 2 | 3 ];
298			output int out0 = [ 1 | 2 | 3 ];
299		}
300
301		both ""
302			#version 100
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 100 es
320		values
321		{
322			input int in0 = [ 1 | 2 | 3 ];
323			output int out0 = [ 1 | 2 | 3 ];
324		}
325
326		both ""
327			#version 100
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 100 es
346		values
347		{
348			input int in0 = [ 1 | 2 | 3 ];
349			output int out0 = [ 1 | 2 | 3 ];
350		}
351
352		both ""
353			#version 100
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 100 es
372		values
373		{
374			input int in0 = [ 1 | 2 | 3 ];
375			output int out0 = [ 1 | 2 | 3 ];
376		}
377
378		both ""
379			#version 100
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 100 es
396		values
397		{
398			input int in0 = [ 1 | 2 | 3 ];
399			output int out0 = [ 1 | 2 | 3 ];
400		}
401
402		both ""
403			#version 100
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 local_variable_hides_function_parameter
418		version 100 es
419		values
420		{
421			input int in0 = [ 1 | 2 | 3 ];
422			output int out0 = [ 1 | 2 | 3 ];
423		}
424
425		both ""
426			#version 100
427			precision mediump float;
428			${DECLARATIONS}
429			int func (int inp, int x) { int x = 5; return inp + x - 5; }
430
431			void main()
432			{
433				${SETUP}
434				out0 = func(in0, 42);
435				${OUTPUT}
436			}
437		""
438	end
439
440end
441
442group invalid "Invalid scoping behavior"
443
444	case redeclare_global_variable
445		version 100 es
446		expect compile_fail
447		both ""
448			#version 100
449			precision mediump float;
450			${DECLARATIONS}
451
452			int a;
453			float a;
454
455			void main()
456			{
457				a = 1.0;
458				${POSITION_FRAG_COLOR} = vec4(a);
459			}
460		""
461	end
462
463	case redeclare_local_variable
464		version 100 es
465		expect compile_fail
466		both ""
467			#version 100
468			precision mediump float;
469			${DECLARATIONS}
470
471			void main()
472			{
473				int a;
474				float a;
475				a = 1.0;
476				${POSITION_FRAG_COLOR} = vec4(a);
477			}
478		""
479	end
480
481	case redeclare_for_init_statement_variable
482		version 100 es
483		expect compile_fail
484		both ""
485			#version 100
486			precision mediump float;
487			${DECLARATIONS}
488
489			void main()
490			{
491				for (int i = 0; i < 10; i++)
492				{
493					int i = 11;
494				}
495				${POSITION_FRAG_COLOR} = vec4(0.0);
496			}
497		""
498	end
499
500	case redeclare_for_condition_variable
501		version 100 es
502		expect compile_fail
503		both ""
504			#version 100
505			precision mediump float;
506			${DECLARATIONS}
507
508			void main()
509			{
510				for (int i = 0; int a = (i < 10); i++)
511				{
512					int a = 0;
513				}
514				${POSITION_FRAG_COLOR} = vec4(0.0);
515			}
516		""
517	end
518
519	case redeclare_for_init_statement_variable_in_for_condition
520		version 100 es
521		expect compile_fail
522		both ""
523			#version 100
524			precision mediump float;
525			${DECLARATIONS}
526
527			void main()
528			{
529				float a;
530				for (int i = 0; int i = (i < 10); i++)
531				{
532					a = sin(i);
533				}
534				${POSITION_FRAG_COLOR} = vec4(a);
535			}
536		""
537	end
538
539	case redeclare_while_condition_variable
540		version 100 es
541		expect compile_fail
542		both ""
543			#version 100
544			precision mediump float;
545			${DECLARATIONS}
546
547			void main()
548			{
549				int a = 0;
550				while (int i = (a < 5))
551				{
552					int i = 11;
553					a += i;
554				}
555				${POSITION_FRAG_COLOR} = vec4(0.0);
556			}
557		""
558	end
559
560	case redeclare_function
561		version 100 es
562		expect compile_fail
563		both ""
564			#version 100
565			precision mediump float;
566			${DECLARATIONS}
567
568			float func(float x);
569			float func(float x);
570
571			float func(float x) { return x + 1.0; }
572
573			void main()
574			{
575				${POSITION_FRAG_COLOR} = vec4(func(1.0));
576			}
577		""
578	end
579
580	case redefine_function
581		version 100 es
582		expect compile_fail
583		both ""
584			#version 100
585			precision mediump float;
586			${DECLARATIONS}
587
588			float func(float x);
589
590			float func(float x) { return x + 1.0; }
591			float func(float x) { return x + 2.0; }
592
593			void main()
594			{
595				${POSITION_FRAG_COLOR} = vec4(func(1.0));
596			}
597		""
598	end
599
600	case redeclare_builtin
601		version 100 es
602		expect compile_fail
603		both ""
604			#version 100
605			precision mediump float;
606			${DECLARATIONS}
607
608			float sin(float x);
609
610			void main()
611			{
612				${POSITION_FRAG_COLOR} = vec4(sin(1.0));
613			}
614		""
615	end
616
617	case redefine_builtin
618		version 100 es
619		expect compile_fail
620		both ""
621			#version 100
622			precision mediump float;
623			${DECLARATIONS}
624
625			float sin(float x) { return x + 1.0; }
626
627			void main()
628			{
629				${POSITION_FRAG_COLOR} = vec4(sin(1.0));
630			}
631		""
632	end
633
634	case conflict_function_struct
635		version 100 es
636		expect compile_fail
637		both ""
638			#version 100
639			precision mediump float;
640			${DECLARATIONS}
641
642			void f(int x);
643			struct f { int x; };
644
645			void main()
646			{
647				${POSITION_FRAG_COLOR} = vec4(1);
648			}
649		""
650	end
651
652	case conflict_function_variable
653		version 100 es
654		expect compile_fail
655		both ""
656			#version 100
657			precision mediump float;
658			${DECLARATIONS}
659
660			void f(int x);
661			float f;
662
663			void main()
664			{
665				f = 1.0;
666				${POSITION_FRAG_COLOR} = vec4(f);
667			}
668		""
669	end
670
671	case use_global_variable_before_declaration
672		version 100 es
673		expect compile_fail
674		both ""
675			#version 100
676			precision mediump float;
677			${DECLARATIONS}
678
679			void func()
680			{
681				a = 2.0;
682			}
683
684			float a;
685
686			void main()
687			{
688				func();
689				${POSITION_FRAG_COLOR} = vec4(a);
690			}
691		""
692	end
693
694	case use_local_variable_before_declaration
695		version 100 es
696		expect compile_fail
697		both ""
698			#version 100
699			precision mediump float;
700			${DECLARATIONS}
701
702			void main()
703			{
704				float a = 1.0;
705				a = b;
706				float b = 2.0;
707
708				${POSITION_FRAG_COLOR} = vec4(a);
709			}
710		""
711	end
712
713	case use_struct_type_before_declaration
714		version 100 es
715		expect compile_fail
716		both ""
717			#version 100
718			precision mediump float;
719			${DECLARATIONS}
720
721			float func (float x) { return S(x).val; }
722			struct S { float val; };
723
724			void main()
725			{
726				${POSITION_FRAG_COLOR} = vec4(func(1.0));
727			}
728		""
729	end
730
731	case use_function_before_declaration
732		version 100 es
733		expect compile_fail
734		both ""
735			#version 100
736			precision mediump float;
737			${DECLARATIONS}
738
739			float func (float x) { return bar(x); }
740			float bar (float x) { return x; }
741
742			void main()
743			{
744				${POSITION_FRAG_COLOR} = vec4(func(1.0));
745			}
746		""
747	end
748
749	case use_variable_from_block_in_outer_scope
750		version 100 es
751		expect compile_fail
752		both ""
753			#version 100
754			precision mediump float;
755			${DECLARATIONS}
756
757			void main()
758			{
759				{
760					float a = 1.0;
761				}
762				${POSITION_FRAG_COLOR} = vec4(a);
763			}
764		""
765	end
766
767	case use_variable_from_if_in_outer_scope
768		version 100 es
769		expect compile_fail
770		both ""
771			#version 100
772			precision mediump float;
773			${DECLARATIONS}
774
775			void main()
776			{
777				if (true)
778					float a = 1.0;
779				${POSITION_FRAG_COLOR} = vec4(a);
780			}
781		""
782	end
783
784	case use_variable_from_else_in_outer_scope
785		version 100 es
786		expect compile_fail
787		both ""
788			#version 100
789			precision mediump float;
790			${DECLARATIONS}
791
792			void main()
793			{
794				if (false)
795					float a = 1.0;
796				else
797					float b = 2.0;
798				${POSITION_FRAG_COLOR} = vec4(b);
799			}
800		""
801	end
802
803	case use_variable_from_if_in_else
804		version 100 es
805		expect compile_fail
806		both ""
807			#version 100
808			precision mediump float;
809			${DECLARATIONS}
810
811			void main()
812			{
813				float a = 1.0;
814				if (true)
815				{
816					float b = 2.0;
817				}
818				else
819				{
820					a = b;
821				}
822				${POSITION_FRAG_COLOR} = vec4(a);
823			}
824		""
825	end
826
827	case use_variable_from_for_init_statement_in_outer_scope
828		version 100 es
829		expect compile_fail
830		both ""
831			#version 100
832			precision mediump float;
833			${DECLARATIONS}
834
835			void main()
836			{
837				float x = 0.0;
838				for (int i = 0; i < 10; i++)
839				{
840					x += sin(i);
841				}
842				${POSITION_FRAG_COLOR} = vec4(float(i));
843			}
844		""
845	end
846
847	case use_variable_from_while_condition_in_outer_scope
848		version 100 es
849		expect compile_fail
850		both ""
851			#version 100
852			precision mediump float;
853			${DECLARATIONS}
854
855			void main()
856			{
857				int a = 1;
858				while (bool b = (a == 1))
859				{
860					a++;
861				}
862				${POSITION_FRAG_COLOR} = vec4(float(b));
863			}
864		""
865	end
866
867	case use_parameter_names_from_function_declaration
868		version 100 es
869		expect compile_fail
870		both ""
871			#version 100
872			precision mediump float;
873			${DECLARATIONS}
874
875			float func(float a, float b);
876
877			float func(float x, float y) { return a+b; }
878
879			void main()
880			{
881				${POSITION_FRAG_COLOR} = vec4(func(1.0, 2.0));
882			}
883		""
884	end
885
886	case variable_not_visible_in_own_initializer
887		version 100 es
888		expect compile_fail
889		both ""
890			#version 100
891			precision mediump float;
892			${DECLARATIONS}
893
894			void main()
895			{
896				float x = x;
897				${POSITION_FRAG_COLOR} = vec4(x);
898			}
899		""
900	end
901
902end # invalid
903