dotnet / interactive

.NET Interactive combines the power of .NET with many other languages to create notebooks, REPLs, and embedded coding experiences. Share code, explore data, write, and learn across your apps in ways you couldn't before.
MIT License
2.91k stars 389 forks source link

Can't use using declaration but have to use block using statement #3691

Closed johngardner58work closed 1 month ago

johngardner58work commented 1 month ago

This form of code using var serilog = new Serilog.LoggerConfiguration(); will complain about a missing ";" but compiles fine in Visual Studio. I have to change it to the statement block form: using(var serilog = new Serilog.LoggerConfiguration()) {...} for it to work in interactive. Since the declaration form is part of C# 12 shouldn't C# script support it also?

Which version of .NET Interactive are you using? (In a notebook, run the #!about magic command. ):

Version: 1.0.522904+cdfa48b2ea1a27dfe0f545c42a34fd3ec7119074

Library version: 1.0.0-beta.24229.4+cdfa48b2ea1a27dfe0f545c42a34fd3ec7119074

Build date: 2024-06-28T23:16:46.5517077Z

Screenshots

If applicable, add screenshots to help explain your problem.

teauxfu commented 1 month ago

I've run into this before as well when trying to use a using declaration for an instance of IDbConnection. Not an expert, but it looks like this might be upstream in Rosyln. If I had to guess the implicit block/scope involved doesn't fit well into the script dialect's syntax tree.

image

Not what you were looking for, but these are the most closely related issues I came across

https://github.com/dotnet/roslyn/issues/16452 https://github.com/dotnet/roslyn/issues/4811

jonsequitur commented 1 month ago

Yes, this issue should be opened on the Roslyn repo.

johngardner58work commented 1 month ago

Thanks!