From 78247954190332eb8c6de8a8df8f7294e3b8c534 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Tue, 3 Dec 2024 13:36:41 +0800 Subject: [PATCH] fix: support "Unsupported" type of fields in "@@index" fixes #1870 --- .../validator/expression-validator.ts | 4 ---- .../validation/datamodel-validation.test.ts | 2 +- tests/regression/tests/issue-1870.test.ts | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 tests/regression/tests/issue-1870.test.ts diff --git a/packages/schema/src/language-server/validator/expression-validator.ts b/packages/schema/src/language-server/validator/expression-validator.ts index d5a11c7b7..06083e9e4 100644 --- a/packages/schema/src/language-server/validator/expression-validator.ts +++ b/packages/schema/src/language-server/validator/expression-validator.ts @@ -59,10 +59,6 @@ export default class ExpressionValidator implements AstValidator { } } - if (expr.$resolvedType?.decl === 'Unsupported') { - accept('error', 'Field of "Unsupported" type cannot be used in expressions', { node: expr }); - } - // extra validations by expression type switch (expr.$type) { case 'BinaryExpr': diff --git a/packages/schema/tests/schema/validation/datamodel-validation.test.ts b/packages/schema/tests/schema/validation/datamodel-validation.test.ts index d89e96a44..fd4274eab 100644 --- a/packages/schema/tests/schema/validation/datamodel-validation.test.ts +++ b/packages/schema/tests/schema/validation/datamodel-validation.test.ts @@ -75,7 +75,7 @@ describe('Data Model Validation Tests', () => { @@allow('all', a == 'a') } `) - ).toMatchObject(errorLike('Field of "Unsupported" type cannot be used in expressions')); + ).toMatchObject(errorLike('incompatible operand types')); }); it('Using `this` in collection predicate', async () => { diff --git a/tests/regression/tests/issue-1870.test.ts b/tests/regression/tests/issue-1870.test.ts new file mode 100644 index 000000000..aa392e54a --- /dev/null +++ b/tests/regression/tests/issue-1870.test.ts @@ -0,0 +1,15 @@ +import { loadModel, loadSchema } from '@zenstackhq/testtools'; + +describe('issue 1870', () => { + it('regression', async () => { + await loadModel( + ` + model Polygon { + id Int @id @default(autoincrement()) + geometry Unsupported("geometry(MultiPolygon, 4326)") + @@index([geometry], name: "parcel_polygon_idx", type: Gist) + } + ` + ); + }); +});