Repository navigation
fix(language): remove this grammar ambiguity in expressions - #2885
Conversation
Allow `this` only as a data field name (for primitive type defs' `this` field) instead of in `RegularID`, which made `this` ambiguous between `ThisExpr` and `ReferenceExpr` and caused Chevrotain to print an "Ambiguous Alternatives" warning whenever a schema used `this` in an expression. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Summary
Follow-up to #2852. Adding
'this'toRegularID(so a primitive type def can declare itsthisfield) madethisambiguous inPrimaryExpr: it could parse as eitherThisExpror aReferenceExpr(viaRegularIDWithTypeNames). Parsing still pickedThisExpr, but because the language module runs in development mode, Chevrotain printed this warning whenever a schema usedthisin an expression, including ordinary policies and validation rules (auth() == this,@@validate(this.age > 0)):This PR removes
'this'fromRegularIDand allows it only as a data field name through a newDataFieldNamerule. Expressions never need to refer to a field namedthisby name, becausethisalways parses asThisExpr. The linker already resolves that to thethisfield's type.Test plan
zen generateon a schema usingthisin a primitive type def (@@validate(isEmail(this))) and in a model (@@validate(this.age > 0)): the warning is gone and generation succeedspackages/languagetests pass (13 files, 132 tests)🤖 Generated with Claude Code
Summary by CodeRabbit
thisalongside existing identifier forms.thisis no longer accepted as a regular identifier in other grammar contexts.