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