1// Expect 3 errors 2 3// Legal cases that should not produce errors: 4void literal_index() { int a[2]; a[0] = 0; a[1] = a[0]; } 5void const_var_index() { int a[2]; const int b = 0; a[b] = 0; } 6void loop_index() { int a[2]; for (int i = 0; i < 2; ++i) { a[i] = i; } } 7void loop_expr_binary() { int a[2]; for (int i = 0; i < 2; ++i) { a[1 - i] = i; } } 8void loop_expr_unary() { int a[2]; for (int i = 0; i > -2; --i) { a[-i] = i; } } 9void loop_swizzle() { int a[2]; for (int i = 0; i < 2; ++i) { a[i.x] = i; } } 10void loop_ternary() { int a[2]; for (int i = 0; i < 2; ++i) { a[i > 0 ? i : 0] = i; } } 11 12void loop_type_coerce() { float a[2]; for (float i = 0; i < 2; ++i) { a[int(i)] = i; } } 13 14void loop_nested() { 15 int a[3]; 16 for (int i = 0; i < 2; ++i) 17 for (int j = 0; j < 2; ++j) { 18 a[i + j] = j; 19 } 20} 21 22uniform int u; 23 24// Illegal cases that should produce errors: 25void uniform_index() { int a[2]; a[u] = 0; } 26void param_index(int p) { int a[2]; a[p] = 0; } 27 28// Legal in SkSL when optimization is enabled: 29void func_index() { int a[2]; a[int(abs(-1))] = 0; } 30