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

Incorrect translation of literal constants used as optional parameter values (when constants are defined in a separate file) #2646

Open
Meertman opened this issue Oct 23, 2019 · 1 comment
Assignees

Comments

@Meertman
Copy link

What You Are Seeing?

When executing a Cake script that includes a custom add-in, the following error is shown:

Compiling build script...
Error: Cake.Core.CakeException: Error(s) occurred when compiling build script:
(2955,122): error CS1009: Unrecognized escape sequence
at Cake.Scripting.Roslyn.RoslynScriptSession.Execute(Script script)
at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments)
at Cake.Commands.BuildCommand.Execute(CakeOptions options)
at Cake.CakeApplication.Run(CakeOptions options)
at Cake.Program.Main()

What is Expected?

The compilation and execution of the build script.

What version of Cake are you using?

I have seen this error with versions 0.29.0, 0.33.0 and 0.35.0

Are you running on a 32 or 64 bit system?

I am running a 64-bit system.

What environment are you running on? Windows? Linux? Mac?

The environment we are running on, is a Windows environment.

Are you running on a CI Server? If so, which one?

The build is both failing on a local machine, as well as on our TeamCity build server.

Additional troubleshooting information

After cloning the Cake github repository, I was able to take a look at the build script that was executed. (Having this in a file for diagnostic purposes would be extremely helpful ;))

This pointed me to a method in our add-in that contained the following signature:

Class A:

[CakeMethodAlias]
public static void DoSomething(this ICakeContext context, string value = Constants.DefaultValue) { ... }

Class B ('Constants'):

public const string DefaultValue = @".\Output";

In the script this got translated to:
[CakeMethodAlias]
public static void DoSomething(this ICakeContext context, string value = ".\Output") { ... }

Note the absence of the literal character '@'.

I managed to work-around this problem by using either of the following implementations in the add-in:

a)

Class A:

[CakeMethodAlias]
public static void DoSomething(this ICakeContext context, string value = default(string))
{
value = value ?? Constants.DefaultValue;
...
}

Class B ('Constants'):

public const string DefaultValue = @".\Output";

b)

Class A:

private const string DefaultValue = @".\Output";

[CakeMethodAlias]
public static void DoSomething(this ICakeContext context, string value = DefaultValue) { ... }

@Meertman
Copy link
Author

Ah so, okay, apparently I haven't tested option B.
What I did test was:

Class A:
private const string DefaultValue = @".\Output";

[CakeMethodAlias]
public static void DoSomething(this ICakeContext context, string value = default(string))
{
value = value ?? DefaultValue;
...
}

@bjorkstromm bjorkstromm self-assigned this Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants