8000 [RFC14] Part 3: Define constraints inside the value type by TungstnBallon · Pull Request #667 · jvalue/jayvee · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[RFC14] Part 3: Define constraints inside the value type #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 12, 2025
Merged

Conversation

TungstnBallon
Copy link
Contributor

Final part of implementing RFC14.
Continues #665.

This PR allows for constraints to be defined inside a value type.

Example of the new syntax:

valuetype SomeName {
    property someAttributeName oftype text;
    constraint shorterThanTen: lengthof someAttributeName < 10;
    constraint isLowercaseAlphabetic: someAttributeName matches /[a-z]+/;
}

@TungstnBallon TungstnBallon self-assigned this Jun 6, 2025
Comment on lines +45 to +46
| ConstraintDefinition
| ValueTypeConstraintInlineDefinition
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future work: this could return a constraint wrapper instead

8000
props,
);
if (isValueTypeConstraintInlineDefinition(constraint)) {
checkConstraintExpression(constraint.expression, props);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we check somewhere that the attribute we refer to in the inline constraint exists?

Copy link
Contributor Author
@TungstnBallon TungstnBallon Jun 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't, but neither for inline definitions nor external definitions.

The code snippets

valuetype VT {
  property id oftype text;
  constraint exactlyTenCharacters: lengthof unknown == 10;
}
valuetype VT {
  property id oftype text;
  constraint len: ExactlyTenCharacters on id;
}

constraint ExactlyTenCharacters on text: lengthof unknown == 10;

both fail during execution with the same message

Could not resolve reference to Referencable named 'unknown'.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to catch this in a validation, so as a language server hint. But can be postponed to a follow-up PR

Copy link
Member
@georg-schwarz georg-schwarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

I'll already approve the PR, so you can merge at your own pace.
Please make sure that at least the validation function I commented on is in place before merging ;-)

@TungstnBallon TungstnBallon merged commit 81f99f8 into main Jun 12, 2025
4 checks passed
@TungstnBallon TungstnBallon deleted the rfc14-3 branch June 12, 2025 13:03
@github-actions github-actions bot locked and limited conversation to collaborators Jun 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0