From 9d86fcda60b2ea804673dd14deec88f25d312157 Mon Sep 17 00:00:00 2001 From: paulklint Date: Sun, 20 Oct 2024 17:26:24 +0200 Subject: [PATCH] Moved code to avoid extend cycle --- .../lang/rascalcore/check/CollectDeclaration.rsc | 11 +++++++++-- .../lang/rascalcore/check/CollectStatement.rsc | 9 ++++++++- .../library/lang/rascalcore/check/ComputeType.rsc | 13 ++----------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc index 1963aa6b..5a54b13d 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc @@ -10,7 +10,7 @@ extend lang::rascalcore::check::CollectDataDeclaration; extend lang::rascalcore::check::CollectSyntaxDeclaration; extend lang::rascalcore::check::Fingerprint; -//extend lang::rascalcore::check::PathAnalysis; +import lang::rascalcore::check::PathAnalysis; //import lang::rascalcore::check::ScopeInfo; import lang::rascalcore::check::CollectOperators; @@ -150,7 +150,14 @@ void collect(current: (Declaration) ` `", initial, [initial, varType], makeVarInitRequirement(var, c)); + if(initial is nonEmptyBlock){ + statements = initial.statements; + Statement stat = (Statement) `{ }`; + if(!returnsValue(stat, "", c)){ + c.report(error(initial, "Right-hand side of assignment does not always have a value")); + } + } + c.require("initialization of ``", initial, [initial, varType], makeVarInitRequirement(var)); collect(initial, c); } c.leaveScope(var); diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectStatement.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectStatement.rsc index fa52c8fe..279831e6 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectStatement.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectStatement.rsc @@ -1165,8 +1165,15 @@ void collect(current: (Statement) ` <{Variable ","}+ variables>;`, if(var is initialized){ initial = var.initial; + if(initial is nonEmptyBlock){ + statements = initial.statements; + Statement stat = (Statement) `{ }`; + if(!returnsValue(stat, "", c)){ + c.report(error(initial, "Right-hand side of assignment does not always have a value")); + } + } c.enterLubScope(var); - c.require("initialization of ``", initial, [initial, varType], makeVarInitRequirement(var, c)); + c.require("initialization of ``", initial, [initial, varType], makeVarInitRequirement(var)); collect(initial, c); c.leaveScope(var); } else { diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/ComputeType.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/ComputeType.rsc index 1cd10163..3141ca89 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/ComputeType.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/ComputeType.rsc @@ -55,16 +55,8 @@ void checkNonVoid(Tree e, AType t, Solver s, str msg){ AType(Solver) makeGetSyntaxType(Type varType) = AType(Solver s) { Tree t = varType; return getSyntaxType(t, s); }; -void(Solver) makeVarInitRequirement(Variable var, Collector c){ - Expression initial = var.initial; - if(initial is nonEmptyBlock){ - statements = initial.statements; - Statement stat = (Statement) `{ }`; - if(!returnsValue(stat, "", c)){ - c.report(error(initial, "Right-hand side of assignment does not always have a value")); - } - } - return void(Solver s){ +void(Solver) makeVarInitRequirement(Variable var) + = void(Solver s){ Bindings bindings = (); initialType = s.getType(var.initial); varType = s.getType(var.name); @@ -86,7 +78,6 @@ void(Solver) makeVarInitRequirement(Variable var, Collector c){ checkNonVoid(var.initial, initialTypeU, s, "Variable initialization"); s.fact(var, deUnique(varType)); }; -} void(Solver) makeNonVoidRequirement(Tree t, str msg) = void(Solver s) { checkNonVoid(t, s, msg ); };