@@ -23,6 +23,7 @@ import * as ast from '../../languages/generated/ast.js';
2323import { getTypeNameWithoutError , hasDataTypeReturn , isPrimitiveGrammarType , isStringGrammarType , resolveImport , resolveTransitiveImports } from '../internal-grammar-util.js' ;
2424import { typeDefinitionToPropertyType } from '../type-system/type-collector/declared-types.js' ;
2525import { flattenPlainType , isPlainReferenceType } from '../type-system/type-collector/plain-types.js' ;
26+ import { AstUtils } from '../../index.js' ;
2627
2728export function registerValidationChecks ( services : LangiumGrammarServices ) : void {
2829 const registry = services . validation . ValidationRegistry ;
@@ -687,11 +688,17 @@ export class LangiumGrammarValidator {
687688 }
688689 return result ;
689690 } ;
690- const isNotAFragment = call . rule . ref !== undefined && ! call . rule . ref . fragment ;
691- const appearsMultipleTimes = findContainerWithCardinality ( call ) !== undefined ;
692- const hasAssignment = call . $container && call . $container . $type === ast . Assignment ;
691+ // Locate called rule, ensure it is not a fragment.
692+ const refersToFragment = call . rule . ref !== undefined && call . rule . ref . fragment ;
693+ // Data type rules do not cause problems, too.
694+ const callInDataTypeRule = ( AstUtils . getContainerOfType ( call , ast . isParserRule ) ) ?. dataType !== undefined ;
695+ if ( refersToFragment || callInDataTypeRule ) {
696+ return ;
697+ }
693698
694- if ( appearsMultipleTimes && ! hasAssignment && isNotAFragment ) {
699+ const appearsMultipleTimes = findContainerWithCardinality ( call ) !== undefined ;
700+ const hasAssignment = AstUtils . getContainerOfType ( call , ast . isAssignment ) !== undefined ;
701+ if ( appearsMultipleTimes && ! hasAssignment ) {
695702 accept ( 'error' , `Rule call ${ call . rule . $refText } requires assignment when used with multiplicity.` , {
696703 node : call ,
697704 property : 'cardinality'
0 commit comments