Module containing a class with the same name results in invalid generated code #4449
Labels
during 2: compilation of correct program
Dafny rejects a valid program during compilation
kind: bug
Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label
lang: c#
Dafny's C# transpiler and its runtime
lang: java
Dafny's Java transpiler and its runtime
lang: js
Dafny's JavaScript transpiler and its runtime
part: code-generation
Support for transpiling Dafny to another language. If relevant, add a `lang:` tag
priority: next
Will consider working on this after in progress work is done
Dafny version
4.2.0
Code to produce this issue
Command to run and resulting output
What happened?
In the generated Python, the
AnyName
class callsAnyName.B()
in itsctor__
function.However,
AnyName
is ambiguous within this function, as it is assigned twice:AnyName = sys.modules[__name__]
class AnyName:
I suspect the generated Python thinks that in
AnyName.B()
,AnyName
is referring to the module, and not the class. However, during execution,AnyName
actually refers to the class here, and the call fails.I would expect to be able to write a class that shares the same name as the module and use other classes within that module.
One workaround might be to append some uncommon string to variable containing the result of the
sys.modules
call, e.g.AnyName_moduleref = sys.modules[__name__]
to differentiate generated references to the module from any references to classes. I modified Dafny-generated code locally to make this change and was able to run thector__
function.What type of operating system are you experiencing the problem on?
Mac
The text was updated successfully, but these errors were encountered: