@@ -108,20 +108,21 @@ export default class ExpressionValidator implements AstValidator<Expression> {
108108 supportedShapes = [ 'Boolean' , 'Any' ] ;
109109 }
110110
111+ const leftResolvedDecl = expr . left . $resolvedType ?. decl ;
112+ const rightResolvedDecl = expr . right . $resolvedType ?. decl ;
113+
111114 if (
112- expr . left . $resolvedType &&
113- ( typeof expr . left . $resolvedType ?. decl !== 'string' ||
114- ! supportedShapes . includes ( expr . left . $resolvedType . decl ) )
115+ leftResolvedDecl &&
116+ ( typeof leftResolvedDecl !== 'string' || ! supportedShapes . includes ( leftResolvedDecl ) )
115117 ) {
116118 accept ( 'error' , `invalid operand type for "${ expr . operator } " operator` , {
117119 node : expr . left ,
118120 } ) ;
119121 return ;
120122 }
121123 if (
122- expr . right . $resolvedType &&
123- ( typeof expr . right . $resolvedType ?. decl !== 'string' ||
124- ! supportedShapes . includes ( expr . right . $resolvedType . decl ) )
124+ rightResolvedDecl &&
125+ ( typeof rightResolvedDecl !== 'string' || ! supportedShapes . includes ( rightResolvedDecl ) )
125126 ) {
126127 accept ( 'error' , `invalid operand type for "${ expr . operator } " operator` , {
127128 node : expr . right ,
@@ -130,14 +131,11 @@ export default class ExpressionValidator implements AstValidator<Expression> {
130131 }
131132
132133 // DateTime comparison is only allowed between two DateTime values
133- if ( expr . left . $resolvedType ?. decl === 'DateTime' && expr . right . $resolvedType ?. decl !== 'DateTime' ) {
134+ if ( leftResolvedDecl === 'DateTime' && rightResolvedDecl && rightResolvedDecl !== 'DateTime' ) {
134135 accept ( 'error' , 'incompatible operand types' , {
135136 node : expr ,
136137 } ) ;
137- } else if (
138- expr . right . $resolvedType ?. decl === 'DateTime' &&
139- expr . left . $resolvedType ?. decl !== 'DateTime'
140- ) {
138+ } else if ( rightResolvedDecl === 'DateTime' && leftResolvedDecl && leftResolvedDecl !== 'DateTime' ) {
141139 accept ( 'error' , 'incompatible operand types' , {
142140 node : expr ,
143141 } ) ;
0 commit comments