Skip to content

csx parsing problems #720

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

Closed
i-mark opened this issue May 14, 2023 · 5 comments · Fixed by #724
Closed

csx parsing problems #720

i-mark opened this issue May 14, 2023 · 5 comments · Fixed by #724

Comments

@i-mark
Copy link

i-mark commented May 14, 2023

I found a few problems with csx parsing:

  1. #load directive with next expression start with string
#nullable enable
#load "ScriptHelper.csx"

"Hello world".Dump();

Produce error:
Could not find file '/Users/mark/Code/CSharpLab/ScriptHelper.csx"'.

Although it works:

#nullable enable
#load "ScriptHelper.csx"

;
"Hello world".Dump();
  1. using statement without parenthesis or a block on top level
using var connection = new SqliteConnection($"Data Source={dbPath}");

Produce errors:
error CS0103: The name 'connection' does not exist in the current context
error CS1002: ; expected

Although it works:

void Func()
{
  using var connection = new SqliteConnection($"Data Source={dbPath}");
}
  1. Reference to Microsoft.NET.Sdk.Web not work · Issue #716 · dotnet-script/dotnet-script
@seesharper
Copy link
Collaborator

@atifaziz Want to take a look at this? 😃

@atifaziz
Copy link
Contributor

@atifaziz Want to take a look at this? 😃

Had a quick look and proposed a fix in PR #724 for the "#load directive with next expression start with string" problem.

  1. using statement without parenthesis or a block on top level

I do believe this is not allowed in a script so not sure anything can be done about it. While not officially documented, see dotnet/roslyn#28588 where it says:

  • test scripting (should disallow using-declaration, maybe some additional complications)

@i-mark
Copy link
Author

i-mark commented May 22, 2023

I try to transform my LINQPad queries to dotnet-script. In LINQPad 1, 2 work without problems.

@atifaziz
Copy link
Contributor

atifaziz commented May 22, 2023

I try to transform my LINQPad queries to dotnet-script. In LINQPad 1, 2 work without problems.

@i-mark LINQPad doesn't use C# scripting like this tool so it's not bound to the same restrictions. LINQPad turns your query/script into a whole C# program, somewhat like what I emulate in LINQPadless.

@i-mark
Copy link
Author

i-mark commented May 22, 2023

I try to transform my LINQPad queries to dotnet-script. In LINQPad 1, 2 work without problems.

@i-mark LINQPad doesn't use C# scripting like this tool so it's not bound to the same restrictions. LINQPad turns your query/script into a whole C# program, somewhat like what I emulate in LINQPadless.

Ok, thx.

I run it with c# scripting and this code throw (1,11): error CS1002

var options = ScriptOptions.Default
		.AddReferences(typeof(Console).Assembly)
		.AddImports("System")
		.AddImports("System.IO");

//var statement = "using (var ms = new System.IO.MemoryStream()) {};";
var statement = "using var ms = new System.IO.MemoryStream();";
await CSharpScript.RunAsync(statement);

@i-mark i-mark closed this as completed May 22, 2023
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

Successfully merging a pull request may close this issue.

3 participants