Add unit test for int/float mismatch error detection.
The "disallowed" tests are largely allowed in the current code, but all fail properly in the followup CL. Change-Id: I8e03570165480b60db9701ac1a782e1124ded56b Bug: skia:11164 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353617 Commit-Queue: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
48c2884c70
commit
e7e68efd9f
@ -103,6 +103,7 @@ sksl_error_tests = [
|
||||
"$_tests/sksl/errors/ForTypeMismatch.sksl",
|
||||
"$_tests/sksl/errors/GenericArgumentMismatch.sksl",
|
||||
"$_tests/sksl/errors/IfTypeMismatch.sksl",
|
||||
"$_tests/sksl/errors/IntFloatMismatch.sksl",
|
||||
"$_tests/sksl/errors/InVarWithInitializerExpression.sksl",
|
||||
"$_tests/sksl/errors/InterfaceBlockScope.sksl",
|
||||
"$_tests/sksl/errors/InterfaceBlockStorageModifiers.sksl",
|
||||
|
34
tests/sksl/errors/IntFloatMismatch.sksl
Normal file
34
tests/sksl/errors/IntFloatMismatch.sksl
Normal file
@ -0,0 +1,34 @@
|
||||
int i = 1;
|
||||
float f = 1.0;
|
||||
|
||||
// SkSL allows `float op <int literal>` and `<int literal> op float`, unlike GLSL.
|
||||
void f_eq_int_literal_ok() { f = 1; }
|
||||
void f_plus_int_literal_ok() { f + 1; }
|
||||
void f_minus_int_literal_ok() { f - 1; }
|
||||
void f_mul_int_literal_ok() { f * 1; }
|
||||
void f_div_int_literal_ok() { f / 1; }
|
||||
void int_literal_plus_f_ok() { 1 + f; }
|
||||
void int_literal_minus_f_ok() { 1 - f; }
|
||||
void int_literal_mul_f_ok() { 1 * f; }
|
||||
void int_literal_div_f_ok() { 1 / f; }
|
||||
|
||||
// Other than int literals, type mixing requires a cast.
|
||||
void i_eq_float_literal_disallowed() { i = 1.0; }
|
||||
void i_eq_f_disallowed() { i = f; }
|
||||
float f_eq_i_disallowed() { f = i; }
|
||||
void i_plus_float_literal_disallowed() { i + 1.0; }
|
||||
void i_minus_float_literal_disallowed() { i - 1.0; }
|
||||
void i_mul_float_literal_disallowed() { i * 1.0; }
|
||||
void i_div_float_literal_disallowed() { i / 1.0; }
|
||||
void float_literal_plus_i_disallowed() { 1.0 + i; }
|
||||
void float_literal_minus_i_disallowed() { 1.0 - i; }
|
||||
void float_literal_mul_i_disallowed() { 1.0 * i; }
|
||||
void float_literal_div_i_disallowed() { 1.0 / i; }
|
||||
void i_plus_f_disallowed() { i + f; }
|
||||
void i_minus_f_disallowed() { i - f; }
|
||||
void i_mul_f_disallowed() { i * f; }
|
||||
void i_div_f_disallowed() { i / f; }
|
||||
void f_plus_i_disallowed() { f + i; }
|
||||
void f_minus_i_disallowed() { f - i; }
|
||||
void f_mul_i_disallowed() { f * i; }
|
||||
void f_div_i_disallowed() { f / i; }
|
5
tests/sksl/errors/golden/IntFloatMismatch.glsl
Normal file
5
tests/sksl/errors/golden/IntFloatMismatch.glsl
Normal file
@ -0,0 +1,5 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 16: type mismatch: '=' cannot operate on 'int', 'float'
|
||||
error: 17: type mismatch: '=' cannot operate on 'int', 'float'
|
||||
2 errors
|
Loading…
Reference in New Issue
Block a user