From fb113b686cf838d03090372813c5ff85311093f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BE=AA?= Date: Mon, 6 Jan 2025 15:59:15 +1100 Subject: [PATCH] resolve: test passed for variable rules --- .../main/java/org/aya/resolve/visitor/ExprResolver.java | 7 +++++-- .../main/java/org/aya/resolve/visitor/StmtResolver.java | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/base/src/main/java/org/aya/resolve/visitor/ExprResolver.java b/base/src/main/java/org/aya/resolve/visitor/ExprResolver.java index 94e46e959..f89d3bdb0 100644 --- a/base/src/main/java/org/aya/resolve/visitor/ExprResolver.java +++ b/base/src/main/java/org/aya/resolve/visitor/ExprResolver.java @@ -280,10 +280,13 @@ private void introduceDependencies(@NotNull GeneralizedVar var) { public @NotNull AnyVar resolve(@NotNull QualifiedID name) { var result = ctx.get(name); if (result instanceof GeneralizedVar gvar) { - // Ensure all dependencies are introduced - introduceDependencies(gvar); var gened = allowedGeneralizes.getOrNull(gvar); if (gened != null) return gened.ref(); + if (!allowGeneralizing) { + ctx.reporter().report(new GeneralizedNotAvailableError(name.sourcePos(), gvar)); + throw new Context.ResolvingInterruptedException(); + } + introduceDependencies(gvar); } return result; } diff --git a/base/src/main/java/org/aya/resolve/visitor/StmtResolver.java b/base/src/main/java/org/aya/resolve/visitor/StmtResolver.java index faf911361..38625d054 100644 --- a/base/src/main/java/org/aya/resolve/visitor/StmtResolver.java +++ b/base/src/main/java/org/aya/resolve/visitor/StmtResolver.java @@ -38,7 +38,8 @@ static void resolveStmt(@NotNull ResolvingStmt stmt, @NotNull ResolveInfo info) case ResolvingStmt.ResolvingDecl decl -> resolveDecl(decl, info); case ResolvingStmt.ModStmt(var stmts) -> resolveStmt(stmts, info); case ResolvingStmt.GenStmt(var variables) -> { - var resolver = new ExprResolver(info.thisModule(), false); + // Create resolver with allowGeneralizing=true for variable declarations + var resolver = new ExprResolver(info.thisModule(), true); resolver.enter(Where.Head); // First pass: register all variables to detect cycles