Skip to content

Commit

Permalink
fix: Support odd characters in pathnames for Go (#4257)
Browse files Browse the repository at this point in the history
Fixes #4120


<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>
  • Loading branch information
RustanLeino authored Jul 24, 2023
1 parent 3b876aa commit 54ccbb8
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 13 deletions.
5 changes: 4 additions & 1 deletion Source/DafnyCore/Compilers/GoLang/Compiler-go.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private struct Import {
protected override void EmitHeader(Program program, ConcreteSyntaxTree wr) {
wr.WriteLine("// Dafny program {0} compiled into Go", program.Name);

ModuleName = MainModuleName = program.MainMethod != null ? "main" : Path.GetFileNameWithoutExtension(program.Name);
ModuleName = MainModuleName = program.MainMethod != null ? "main" : TransformToClassName(Path.GetFileNameWithoutExtension(program.Name));

wr.WriteLine("package {0}", ModuleName);
wr.WriteLine();
Expand Down Expand Up @@ -109,6 +109,9 @@ void EmitImports(ConcreteSyntaxTree wr, out ConcreteSyntaxTree importWriter, out
}
}

public static string TransformToClassName(string baseName) =>
Regex.Replace(baseName, "[^_A-Za-z0-9$]", "_");

public override void EmitCallToMain(Method mainMethod, string baseName, ConcreteSyntaxTree wr) {
var companion = TypeName_Companion(UserDefinedType.FromTopLevelDeclWithAllBooleanTypeParameters(mainMethod.EnclosingClass), wr, mainMethod.tok, mainMethod);

Expand Down
2 changes: 0 additions & 2 deletions Test/dafny4/git-issue105.dfy.go.check

This file was deleted.

3 changes: 0 additions & 3 deletions Test/dafny4/git-issue43.dfy.go.check

This file was deleted.

3 changes: 0 additions & 3 deletions Test/dafny4/git-issue79.dfy.go.check

This file was deleted.

2 changes: 0 additions & 2 deletions Test/git-issues/git-issue-2441.dfy.go.check

This file was deleted.

2 changes: 0 additions & 2 deletions Test/git-issues/github-issue-3343.dfy.go.check

This file was deleted.

1 change: 1 addition & 0 deletions docs/dev/news/4257.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support odd characters in pathnames for Go

0 comments on commit 54ccbb8

Please sign in to comment.