Skip to content

Commit b67728c

Browse files
committed
fix test and clean up
1 parent 465956a commit b67728c

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

packages/schema/src/language-server/validator/expression-validator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
DataModelAttribute,
55
Expression,
66
ExpressionType,
7+
isAliasDecl,
78
isArrayExpr,
89
isDataModel,
910
isDataModelAttribute,
@@ -21,7 +22,7 @@ import {
2122
isDataModelFieldReference,
2223
isEnumFieldReference,
2324
} from '@zenstackhq/sdk';
24-
import { ValidationAcceptor, streamAst } from 'langium';
25+
import { ValidationAcceptor, getContainerOfType, streamAst } from 'langium';
2526
import { findUpAst, getContainingDataModel } from '../../utils/ast-utils';
2627
import { AstValidator } from '../types';
2728
import { isAuthOrAuthMemberAccess, typeAssignable } from './utils';
@@ -33,7 +34,7 @@ export default class ExpressionValidator implements AstValidator<Expression> {
3334
validate(expr: Expression, accept: ValidationAcceptor): void {
3435
// deal with a few cases where reference resolution fail silently
3536
if (!expr.$resolvedType) {
36-
if (isAuthInvocation(expr)) {
37+
if (isAuthInvocation(expr) && !getContainerOfType(expr, isAliasDecl)) {
3738
// check was done at link time
3839
accept(
3940
'error',

packages/schema/src/language-server/zmodel-linker.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
DataModelFieldType,
1111
Enum,
1212
EnumField,
13-
Expression,
1413
ExpressionType,
1514
FunctionDecl,
1615
FunctionParam,
@@ -333,9 +332,8 @@ export class ZModelLinker extends DefaultLinker {
333332
getModelFieldsWithBases(containingModel).find((field) => field.name === name);
334333

335334
// Ensure the alias expression is fully resolved in the current context
336-
this.resolveExpressionInContext(matchingAlias.expression, document, containingModel, [
337-
scopeProvider,
338-
]);
335+
// Pass both the model scope and existing extraScopes
336+
this.resolve(matchingAlias.expression, document, [scopeProvider, ...extraScopes]);
339337
}
340338
}
341339
} else {
@@ -472,16 +470,6 @@ export class ZModelLinker extends DefaultLinker {
472470
node.$resolvedType = node.value.$resolvedType;
473471
}
474472

475-
private resolveExpressionInContext(
476-
expr: Expression,
477-
document: LangiumDocument<AstNode>,
478-
contextModel: DataModel,
479-
extraScopes: ScopeProvider[]
480-
) {
481-
// Resolve the expression with the model context scope
482-
this.resolve(expr, document, extraScopes);
483-
}
484-
485473
private unresolvableRefExpr(item: ReferenceExpr) {
486474
const ref = item.target as DefaultReference;
487475
ref._ref = this.createLinkingError({
@@ -569,10 +557,6 @@ export class ZModelLinker extends DefaultLinker {
569557
//#region Utils
570558

571559
private resolveToDeclaredType(node: AstNode, type: FunctionParamType | DataModelFieldType | TypeDefFieldType) {
572-
// enums from alias expressions are already resolved and do not exist in the scope
573-
if (!type) {
574-
return;
575-
}
576560
let nullable = false;
577561
if (isDataModelFieldType(type) || isTypeDefField(type)) {
578562
nullable = type.optional;

0 commit comments

Comments
 (0)