Skip to content

Commit

Permalink
fix: Apply name mangling to datatype names in Python more often (#5476)
Browse files Browse the repository at this point in the history
Fixes #5469

---------

Co-authored-by: Remy Willems <[email protected]>
  • Loading branch information
fabiomadge and keyboardDrummer authored May 22, 2024
1 parent 4ce2f7e commit 412f10e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/DafnyCore/Backends/Python/PythonCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ private void DatatypeFieldsAndConstructor(DatatypeCtor ctor, ConcreteSyntaxTree

private string DtCtorDeclarationName(DatatypeCtor ctor, bool full = false) {
var dt = ctor.EnclosingDatatype;
return $"{(full ? dt.GetFullCompileName(Options) : dt.GetCompileName(Options))}_{ctor.GetCompileName(Options)}";
return $"{(full ? dt.GetFullCompileName(Options) : IdProtect(dt.GetCompileName(Options)))}_{ctor.GetCompileName(Options)}";
}

protected IClassWriter DeclareType(TopLevelDecl d, SubsetTypeDecl.WKind witnessKind, Expression witness, ConcreteSyntaxTree wr) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %testDafnyForEachCompiler --refresh-exit-code=0 "%s"

module SomeDependencyModule {
datatype None = None
}

module SomeModule {
import SomeDependencyModule

const test := SomeDependencyModule.None
}

method Main() {
print SomeModule.test, "\n";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SomeDependencyModule.None.None
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHECK: error
1 change: 1 addition & 0 deletions docs/dev/news/5476.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Apply name mangling to datatype names in Python more often

0 comments on commit 412f10e

Please sign in to comment.