From 76eb31b52fc8b392a153dcb781551ee75188d991 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Wed, 9 Sep 2026 20:39:52 -0700 Subject: [PATCH] fix(language): resolve `@uuid` version arg by name in validation `_checkUuid` assumed the version was `attr.args[0]`, so a named application like `@uuid(message: '...', version: 1)` skipped validation entirely. Look up the arg whose resolved param is `version` and use it for both the value and the diagnostic location. Co-Authored-By: Claude Opus 5 (1M context) --- .../attribute-application-validator.ts | 8 +++- .../test/attribute-application.test.ts | 44 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/packages/language/src/validators/attribute-application-validator.ts b/packages/language/src/validators/attribute-application-validator.ts index 17d1b9904..cdb0ed969 100644 --- a/packages/language/src/validators/attribute-application-validator.ts +++ b/packages/language/src/validators/attribute-application-validator.ts @@ -463,9 +463,13 @@ export default class AttributeApplicationValidator implements AstValidator arg.$resolvedParam?.name === 'version'); + if (!versionArg) { + return; + } + const version = getNumberLiteral(versionArg.value); if (version !== undefined && version !== 4 && version !== 7) { - accept('error', `\`@uuid\` version must be \`4\` or \`7\``, { node: attr.args[0]! }); + accept('error', `\`@uuid\` version must be \`4\` or \`7\``, { node: versionArg }); } } diff --git a/packages/language/test/attribute-application.test.ts b/packages/language/test/attribute-application.test.ts index 190e4096f..9abe8ffe9 100644 --- a/packages/language/test/attribute-application.test.ts +++ b/packages/language/test/attribute-application.test.ts @@ -661,6 +661,50 @@ describe('Attribute application validation tests', () => { /`@uuid` version must be `4` or `7`/, ); }); + + it('resolves the version arg by name regardless of argument order', async () => { + await loadSchema( + ` + datasource db { + provider = 'sqlite' + url = 'file:./dev.db' + } + + model User { + id String @id @uuid(message: 'invalid uuid', version: 7) + } + `, + ); + + await loadSchemaWithError( + ` + datasource db { + provider = 'sqlite' + url = 'file:./dev.db' + } + + model User { + id String @id @uuid(message: 'invalid uuid', version: 1) + } + `, + /`@uuid` version must be `4` or `7`/, + ); + }); + + it('does not treat a message-only arg as a version', async () => { + await loadSchema( + ` + datasource db { + provider = 'sqlite' + url = 'file:./dev.db' + } + + model User { + id String @id @uuid(message: 'invalid uuid') + } + `, + ); + }); }); describe('Native type mapping attributes', () => {