Throws when passing an empty array into an attribute
orta opened this issue · 3 comments
Hi there! I've been trying to write a PR for this but haven't quite figured out where the issues lays, so I thought I should write an issue while it is fresh and hopefully I can rubber duck myself into an answer.
datasource db {
provider = "postgres"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
binaryTargets = "native"
}
model UserProfile {
userID String @id @unique
/// A one liner
bio String?
/// Hrefs which show under the user
links String[] @default([])
}
Will throw due to links String[] @default([])
. It throws in:
this.OPTION(() => {
this.CONSUME(lexer.LRound);
this.MANY_SEP({
SEP: lexer.Comma,
DEF: () => {
this.SUBRULE(this.attributeArg);
},
});
this.CONSUME(lexer.RRound);
});
Which feels a bit odd because this.attributeArg
eventually includes this.array
which should be able to handle the empty array judging by the JSON parser in the playground which has the same definition code.
Converting it to links String[] @default([""])
passes, but would have different runtime behaviours.
Things I've tried:
- Defining an 'empty array' parse rule for it
- Adding array specifically to the attributeArg fn
Thanks for the report 👍 I'll take a look at this when I get a chance
@orta this is fixed in v0.4.2. Turns out I had an Array symbol in the lexer, which was '[]'
, intended to be used in the field parsing logic (e.g. for columns such as String[]
). Anyway, the lexer was picking up @default([])
and assigning the Array symbol to it, which caused it to skip over the this.array
rule.
I removed the Array symbol and switched the field rule to consume the '['
and ']'
symbols individually.