diff --git a/packages/schema/src/language-server/validator/expression-validator.ts b/packages/schema/src/language-server/validator/expression-validator.ts index 21548c89f..557b0f338 100644 --- a/packages/schema/src/language-server/validator/expression-validator.ts +++ b/packages/schema/src/language-server/validator/expression-validator.ts @@ -64,6 +64,16 @@ export default class ExpressionValidator implements AstValidator { case '<=': case '&&': case '||': { + if (expr.left.$resolvedType?.array) { + accept('error', 'operand cannot be an array', { node: expr.left }); + break; + } + + if (expr.right.$resolvedType?.array) { + accept('error', 'operand cannot be an array', { node: expr.right }); + break; + } + let supportedShapes: ExpressionType[]; if (['>', '>=', '<', '<='].includes(expr.operator)) { supportedShapes = ['Int', 'Float', 'DateTime', 'Any']; @@ -105,6 +115,11 @@ export default class ExpressionValidator implements AstValidator { case '==': case '!=': { + if (!!expr.left.$resolvedType?.array !== !!expr.right.$resolvedType?.array) { + accept('error', 'incompatible operand types', { node: expr }); + break; + } + // disallow comparing model type with scalar type or comparison between // incompatible model types const leftType = expr.left.$resolvedType?.decl; diff --git a/packages/schema/tests/schema/validation/attribute-validation.test.ts b/packages/schema/tests/schema/validation/attribute-validation.test.ts index cc908898b..5c638a841 100644 --- a/packages/schema/tests/schema/validation/attribute-validation.test.ts +++ b/packages/schema/tests/schema/validation/attribute-validation.test.ts @@ -553,6 +553,50 @@ describe('Attribute tests', () => { `) ).toContain('incompatible operand types'); + expect( + await loadModelWithError(` + ${prelude} + model A { + id String @id + x Int + y Int[] + + @@allow(true, x == y) + } + `) + ).toContain('incompatible operand types'); + + expect( + await loadModelWithError(` + ${prelude} + model A { + id String @id + x Int + y Int[] + + @@allow(true, x > y) + } + `) + ).toContain('operand cannot be an array'); + + expect( + await loadModelWithError(` + ${prelude} + model User { + id Int @id + foo Foo @relation(fields: [fooId], references: [id]) + fooId Int + } + + model Foo { + id Int @id + users User[] + + @@allow('all', users == auth()) + } + `) + ).toContain('incompatible operand types'); + expect( await loadModelWithError(` ${prelude}