Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support odd characters in pathnames for Go #4257

Merged
merged 12 commits into from
Jul 24, 2023
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