diff --git a/packages/schema/src/language-server/validator/attribute-application-validator.ts b/packages/schema/src/language-server/validator/attribute-application-validator.ts index ea202f7f5..f81f5c166 100644 --- a/packages/schema/src/language-server/validator/attribute-application-validator.ts +++ b/packages/schema/src/language-server/validator/attribute-application-validator.ts @@ -179,12 +179,31 @@ function assignableToAttributeParam(arg: AttributeArg, param: AttributeParam, at let dstType = param.type.type; let dstIsArray = param.type.array; + + if (dstType === 'ContextType') { + // ContextType is inferred from the attribute's container's type + if (isDataModelField(attr.$container)) { + dstIsArray = attr.$container.type.array; + } + } + const dstRef = param.type.reference; if (dstType === 'Any' && !dstIsArray) { return true; } + if (argResolvedType.decl === 'Any') { + // arg is any type + if (!argResolvedType.array) { + // if it's not an array, it's assignable to any type + return true; + } else { + // otherwise it's assignable to any array type + return argResolvedType.array === dstIsArray; + } + } + // destination is field reference or transitive field reference, check if // argument is reference or array or reference if (dstType === 'FieldReference' || dstType === 'TransitiveFieldReference') { diff --git a/tests/integration/tests/regression/issue-947.test.ts b/tests/integration/tests/regression/issue-947.test.ts new file mode 100644 index 000000000..afabae502 --- /dev/null +++ b/tests/integration/tests/regression/issue-947.test.ts @@ -0,0 +1,19 @@ +import { loadModel } from '@zenstackhq/testtools'; + +describe('Regression: issue 947', () => { + it('regression', async () => { + await loadModel( + ` + model Test { + id String @id + props TestEnum[] @default([]) + } + + enum TestEnum { + A + B + } + ` + ); + }); +});