Skip to content

Commit 16afdc8

Browse files
authored
Fix: --compile-suffix avoids the extra renaming of homonymous classes (#6073)
Fixes #6072 ### What was changed? I changed it so that the comparison between the module name and the class name is done on the C# string, not the Dafny string vs. C# string. ### How has this been tested? I added a check to ensure that in the generated C# code, the class named `A` is not escaped when using `--compile-suffix` <small>By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
1 parent 0460827 commit 16afdc8

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Source/DafnyCore/Backends/CSharp/CsharpCodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ protected override ConcreteSyntaxTree CreateStaticMain(IClassWriter cw, string a
270270
/// </summary>
271271
private string protectedTypeName(TopLevelDecl dt) {
272272
var protectedName = IdName(dt);
273-
if (dt.EnclosingModuleDefinition is { Name: var moduleName } && moduleName == protectedName) {
273+
if (dt.EnclosingModuleDefinition.GetCompileName(Options) == protectedName) {
274274
return $"_{protectedName}";
275275
}
276276
return protectedName;

Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-6014.dfy

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
// RUN: %testDafnyForEachCompiler --refresh-exit-code=0 "%s"
1+
// RUN: %testDafnyForEachCompiler --refresh-exit-code=0 "%s"
2+
// Extra check for the C# compiler with the --compile-suffix option.
3+
// RUN: %baredafny build -t:cs --compile-suffix "%s"
4+
// RUN: %OutputCheck --file-to-check "%S/git-issue-6014.cs" "%s"
5+
// Just to make sure that if we use --compile-suffix, we don't do the escape
6+
// CHECK: .*A_Compile\.A.*
7+
// With the class named B_Compile, it becomes B__Compile so there should be no conflict
8+
// Adding this test in case someone changes the underscore escaping rules to account for this possibility
9+
// CHECK: .*B_Compile\.B__Compile.*
10+
211

312
module State {
413

@@ -23,6 +32,9 @@ module Enclosing {
2332
datatype A = Whatever
2433
}
2534

35+
module B {
36+
datatype B_Compile = Whatever
37+
}
2638
}
2739

2840
module UsingEnclosing {

0 commit comments

Comments
 (0)