From 730fa76a788810cc86d555f44042f3de27205667 Mon Sep 17 00:00:00 2001 From: paulklint Date: Mon, 4 Nov 2024 22:56:50 +0100 Subject: [PATCH] Fixed exceptional case of nested clones Fixes #2067 Unfortunately this will change the md5 hash of functions. --- .../rascalcore/check/CollectDeclaration.rsc | 22 +++++---------- .../check/tests/ChangeAndHashTests.rsc | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+), 15 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 5a54b13d..b19ff13e 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectDeclaration.rsc @@ -37,15 +37,12 @@ import util::Reflective; // ---- Rascal declarations --------------------------------------------------- -int localFunCounter = 0; - void collect(Module current: (Module) `
`, Collector c){ dataCounter = 0; variantCounter = 0; nalternatives = 0; syndefCounter = 0; - localFunCounter = 0; mloc = getLoc(current); mname = prettyPrintName(header.name); @@ -240,12 +237,13 @@ void collect(current: (FunctionDeclaration) ``, Collec c.report(info(current, "Ignoring function declaration for ``")); return; } - // Make md5hash of nested functions unique with counter - if(size(c.getStack(currentFunction)) > 0){ - localFunCounter += 1; + // Make md5hash of nested functions unique by using all surrounding signatures + c.push(currentFunction, current); + allSignatures = ""; + for(FunctionDeclaration outerFun <- c.getStack(currentFunction)){ + allSignatures += md5Contrib4signature(outerFun.signature); } - c.push(currentFunction, ppfname); - md5Contrib = "-"; + md5Contrib = ""; = getExpected(decl.tags); if(expected){ @@ -381,16 +379,10 @@ void collect(current: (FunctionDeclaration) ``, Collec endUseBoundedTypeParameters(c); - surroundingFuns = c.getStack(currentFunction); - - dt.md5 = md5Hash(size(surroundingFuns) == 1 ? md5Contrib : ""); + dt.md5 = md5Hash(md5Contrib); c.defineInScope(parentScope, prettyPrintName(fname), functionId(), current, dt); - // println(" =\> "); c.leaveScope(decl); c.pop(currentFunction); - if(size(c.getStack(currentFunction)) == 0){ - localFunCounter = 0; - } } void collect(current: (FunctionBody) `{ }`, Collector c){ diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/tests/ChangeAndHashTests.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/tests/ChangeAndHashTests.rsc index 21887120..f2f73afc 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/tests/ChangeAndHashTests.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/tests/ChangeAndHashTests.rsc @@ -13,6 +13,8 @@ import Map; import Set; import lang::rascalcore::check::ATypeBase; +import lang::rascalcore::check::tests::StaticTestingUtils; + TModel check(str moduleName, RascalCompilerConfig compilerConfig){ ModuleStatus ms = rascalTModelForNames([moduleName], @@ -217,6 +219,31 @@ test bool funDeleted() = expectSuperset("int f(int n) = n + 1; int g(int n) = n + 2;", "int f(int n) = n + 1;"); +test bool nestedCloneOK() = checkOK(" + void foo(str _){ + int bar(){ + return 1; + } + bar(); + } + + void foo(int _){ + int bar(){ + return 1; + } + bar(); + }"); + +test bool clonesNotOK() = unexpectedDeclarationInModule(" + module TwoBars + int bar(int _){ + return 1; + } + int bar(int _){ + return 2; + } + "); + // Data declarations test bool commonKwFieldAdded()