Skip to content

Commit 2acfcdb

Browse files
chunkerchunkerymc9
andauthored
bugfix: allow empty array default (#948)
Co-authored-by: Yiming <yiming@whimslab.io> Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
1 parent c4c066d commit 2acfcdb

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

packages/schema/src/language-server/validator/attribute-application-validator.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,31 @@ function assignableToAttributeParam(arg: AttributeArg, param: AttributeParam, at
179179

180180
let dstType = param.type.type;
181181
let dstIsArray = param.type.array;
182+
183+
if (dstType === 'ContextType') {
184+
// ContextType is inferred from the attribute's container's type
185+
if (isDataModelField(attr.$container)) {
186+
dstIsArray = attr.$container.type.array;
187+
}
188+
}
189+
182190
const dstRef = param.type.reference;
183191

184192
if (dstType === 'Any' && !dstIsArray) {
185193
return true;
186194
}
187195

196+
if (argResolvedType.decl === 'Any') {
197+
// arg is any type
198+
if (!argResolvedType.array) {
199+
// if it's not an array, it's assignable to any type
200+
return true;
201+
} else {
202+
// otherwise it's assignable to any array type
203+
return argResolvedType.array === dstIsArray;
204+
}
205+
}
206+
188207
// destination is field reference or transitive field reference, check if
189208
// argument is reference or array or reference
190209
if (dstType === 'FieldReference' || dstType === 'TransitiveFieldReference') {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { loadModel } from '@zenstackhq/testtools';
2+
3+
describe('Regression: issue 947', () => {
4+
it('regression', async () => {
5+
await loadModel(
6+
`
7+
model Test {
8+
id String @id
9+
props TestEnum[] @default([])
10+
}
11+
12+
enum TestEnum {
13+
A
14+
B
15+
}
16+
`
17+
);
18+
});
19+
});

0 commit comments

Comments
 (0)