Skip to content

Commit

Permalink
Fixed exceptional case of nested clones
Browse files Browse the repository at this point in the history
Fixes #2067

Unfortunately this will change the md5 hash of functions.
  • Loading branch information
PaulKlint committed Nov 4, 2024
1 parent 7efcea3 commit 730fa76
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ import util::Reflective;

// ---- Rascal declarations ---------------------------------------------------

int localFunCounter = 0;

void collect(Module current: (Module) `<Header header> <Body body>`, Collector c){

dataCounter = 0;
variantCounter = 0;
nalternatives = 0;
syndefCounter = 0;
localFunCounter = 0;

mloc = getLoc(current);
mname = prettyPrintName(header.name);
Expand Down Expand Up @@ -240,12 +237,13 @@ void collect(current: (FunctionDeclaration) `<FunctionDeclaration decl>`, Collec
c.report(info(current, "Ignoring function declaration for `<decl.signature.name>`"));
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 = "<md5Contrib4Tags(decl.tags)><decl.visibility><md5Contrib4signature(signature)>-<localFunCounter>";
md5Contrib = "<md5Contrib4Tags(decl.tags)><decl.visibility><allSignatures>";

<expected, expectedTagString> = getExpected(decl.tags);
if(expected){
Expand Down Expand Up @@ -381,16 +379,10 @@ void collect(current: (FunctionDeclaration) `<FunctionDeclaration decl>`, Collec
endUseBoundedTypeParameters(c);
surroundingFuns = c.getStack(currentFunction);
dt.md5 = md5Hash(size(surroundingFuns) == 1 ? md5Contrib : "<intercalate("/", surroundingFuns)><md5Contrib>");
dt.md5 = md5Hash(md5Contrib);
c.defineInScope(parentScope, prettyPrintName(fname), functionId(), current, dt);
// println("<md5Contrib> =\> <dt.md5>");
c.leaveScope(decl);
c.pop(currentFunction);
if(size(c.getStack(currentFunction)) == 0){
localFunCounter = 0;
}
}
void collect(current: (FunctionBody) `{ <Statement* statements> }`, Collector c){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 730fa76

Please sign in to comment.