Conversation
perminder-17
left a comment
There was a problem hiding this comment.
Hi, thanks for your work on this! Do you think it would be worth adding two more cases?
- Comparing two boolean values using <, etc. such as a < b where both a and b are booleans.
- Comparing a boolean with a number using equalTo() or notEqual().
Both are invalid in GLSL, so catching them early with a strands error would be helpful? what do you think
|
hi @perminder-17 , thanks for suggesting both cases. yes we should catch them early to log friendly errors. happy to push follow up commit. |
perminder-17
left a comment
There was a problem hiding this comment.
If you look at lines 177 to 183 in ir_builders.js
if (leftType.dimension === 1 && rightType.dimension > 1) {
cast.node = leftStrandsNode;
cast.toType = rightType;
} else if (rightType.dimension === 1 && leftType.dimension > 1) {
cast.node = rightStrandsNode;
cast.toType = leftType;This code does type casting, where the dimensions get equalized. Because of this, the error message can become confusing.
For example:
if (color < 2) {
// ...some operations
}Currently we get: < is only defined for scalars. Got float4 < float4. But this is misleading, we should instead get Got float4 < float1, since that reflects the user's original types, not the post-cast types.
Can we take a snapshot of the original types before the typecasting happens, and use that snapshot in all the error messages, so this confusion doesn't happen? @skyyash Let me know what you think?
|
@perminder-17 good catch, (i didnt noticed it). when the pre-cast type is preCastLeftType.baseType === BaseType.DEFER ? leftBase : preCastLeftType.baseTypesince |
Sounds good to me! |
Resolves #8445
Changes:
binaryOpNode.<,<=,>,>=) are now rejected when either operand is a vector, matching glsl rules.PR Checklist
npm run lintpasses