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

Track nullability in script code #33096

Merged
merged 13 commits into from
Mar 26, 2019
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/BinderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal Binder GetBinder(SyntaxNode node, CSharpSyntaxNode memberDeclarationOpt
// Unless this is interactive retrieving a binder for global statements
// at the very top-level (i.e. in a completely empty file) use
// node.Parent to maintain existing behavior.
if (!InScript || node.Kind() != SyntaxKind.CompilationUnit)
if ((!InScript || node.Kind() != SyntaxKind.CompilationUnit) && node.Parent != null)
filipw marked this conversation as resolved.
Show resolved Hide resolved
{
node = node.Parent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ internal static void Analyze(
DiagnosticBag diagnostics,
Action<BoundExpression, TypeSymbolWithAnnotations> callbackOpt = null)
{
if (method.IsImplicitlyDeclared && (!method.IsImplicitConstructor || method.ContainingType.IsImplicitlyDeclared))
if (method.IsImplicitlyDeclared && !method.IsImplicitConstructor && !method.IsScriptInitializer)
{
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Scripting/CSharp/CSharpScriptCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class CSharpScriptCompiler : ScriptCompiler
{
public static readonly ScriptCompiler Instance = new CSharpScriptCompiler();

private static readonly CSharpParseOptions s_defaultOptions = new CSharpParseOptions(kind: SourceCodeKind.Script, languageVersion: LanguageVersion.Latest);
internal static readonly CSharpParseOptions DefaultParseOptions = new CSharpParseOptions(kind: SourceCodeKind.Script, languageVersion: LanguageVersion.Latest);

private CSharpScriptCompiler()
{
Expand All @@ -23,8 +23,8 @@ private CSharpScriptCompiler()

public override bool IsCompleteSubmission(SyntaxTree tree) => SyntaxFactory.IsCompleteSubmission(tree);

public override SyntaxTree ParseSubmission(SourceText text, CancellationToken cancellationToken) =>
SyntaxFactory.ParseSyntaxTree(text, s_defaultOptions, cancellationToken: cancellationToken);
public override SyntaxTree ParseSubmission(SourceText text, ParseOptions parseOptions, CancellationToken cancellationToken) =>
SyntaxFactory.ParseSyntaxTree(text, parseOptions ?? DefaultParseOptions, cancellationToken: cancellationToken);

public override Compilation CreateSubmission(Script script)
{
Expand All @@ -40,7 +40,7 @@ public override Compilation CreateSubmission(Script script)
// TODO: report diagnostics
diagnostics.Free();

var tree = SyntaxFactory.ParseSyntaxTree(script.SourceText, s_defaultOptions, script.Options.FilePath);
var tree = SyntaxFactory.ParseSyntaxTree(script.SourceText, script.Options.ParseOptions ?? DefaultParseOptions, script.Options.FilePath);

string assemblyName, submissionTypeName;
script.Builder.GenerateSubmissionId(out assemblyName, out submissionTypeName);
Expand Down
14 changes: 11 additions & 3 deletions src/Scripting/CSharp/CSharpScriptingResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions src/Scripting/CSharp/CSharpScriptingResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,24 @@
<value>Copyright (C) Microsoft Corporation. All rights reserved.</value>
</data>
<data name="InteractiveHelp" xml:space="preserve">
<value><![CDATA[Usage: csi [option] ... [script-file.csx] [script-argument] ...
filipw marked this conversation as resolved.
Show resolved Hide resolved
filipw marked this conversation as resolved.
Show resolved Hide resolved
<value>Usage: csi [option] ... [script-file.csx] [script-argument] ...

Executes script-file.csx if specified, otherwise launches an interactive REPL (Read Eval Print Loop).
filipw marked this conversation as resolved.
Show resolved Hide resolved

Options:
/help Display this usage message (alternative form: /?)
/version Display the version and exit
/i Drop to REPL after executing the specified script.
/r:<file> Reference metadata from the specified assembly file (alternative form: /reference)
/r:<file list> Reference metadata from the specified assembly files (alternative form: /reference)
/lib:<path list> List of directories where to look for libraries specified by #r directive.
/r:&lt;file&gt; Reference metadata from the specified assembly file (alternative form: /reference)
/r:&lt;file list&gt; Reference metadata from the specified assembly files (alternative form: /reference)
/lib:&lt;path list&gt; List of directories where to look for libraries specified by #r directive.
(alternative forms: /libPath /libPaths)
/u:<namespace> Define global namespace using (alternative forms: /using, /usings, /import, /imports)
@<file> Read response file for more options
/u:&lt;namespace&gt; Define global namespace using (alternative forms: /using, /usings, /import, /imports)
@&lt;file&gt; Read response file for more options
-- Indicates that the remaining arguments should not be treated as options.
]]></value>
</value>
</data>
<data name="CannotSetCSharpLanguageVersion" xml:space="preserve">
<value>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</value>
filipw marked this conversation as resolved.
Show resolved Hide resolved
</data>
</root>
3 changes: 2 additions & 1 deletion src/Scripting/CSharp/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

Microsoft.CodeAnalysis.CSharp.Scripting.ScriptOptionsExtensions
static Microsoft.CodeAnalysis.CSharp.Scripting.ScriptOptionsExtensions.WithLanguageVersion(this Microsoft.CodeAnalysis.Scripting.ScriptOptions options, Microsoft.CodeAnalysis.CSharp.LanguageVersion languageVersion) -> Microsoft.CodeAnalysis.Scripting.ScriptOptions
19 changes: 19 additions & 0 deletions src/Scripting/CSharp/ScriptOptionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.CodeAnalysis.Scripting;

namespace Microsoft.CodeAnalysis.CSharp.Scripting
{
public static class ScriptOptionsExtensions
{
public static ScriptOptions WithLanguageVersion(this ScriptOptions options, LanguageVersion languageVersion)
{
var parseOptions = (options.ParseOptions is null)
? CSharpScriptCompiler.DefaultParseOptions
: (options.ParseOptions is CSharpParseOptions existing) ? existing : throw new InvalidOperationException(CSharpScriptingResources.CannotSetCSharpLanguageVersion);

return options.WithParseOptions(parseOptions.WithLanguageVersion(languageVersion));
}
}
}
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Verze kompilátoru Microsoft (R) Visual C# Interactive {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# Interactive – Compilerversion {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Compilador de Microsoft (R) Visual C# interactivo, versión {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Compilateur Microsoft (R) Visual C# Interactive version {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="it" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Compilatore Microsoft (R) Visual C# Interactive versione {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ja" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# インタラクティブ コンパイラ バージョン {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ko" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# 대화형 컴파일러 버전 {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pl" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# Interactive — wersja kompilatora {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pt-BR" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Versão {0} do Compilador C# Interativo do Microsoft (R) Visual</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ru" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Компилятор Microsoft (R) Visual C# Interactive версии {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="tr" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# Etkileşimli Derleyici sürümü {0}</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Scripting/CSharp/xlf/CSharpScriptingResources.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hans" original="../CSharpScriptingResources.resx">
<body>
<trans-unit id="CannotSetCSharpLanguageVersion">
<source>Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</source>
<target state="new">Cannot set C# LanguageVersion because ParseOptions were already configured for a different language.</target>
<note />
</trans-unit>
<trans-unit id="LogoLine1">
<source>Microsoft (R) Visual C# Interactive Compiler version {0}</source>
<target state="translated">Microsoft (R) Visual C# 交互窗口编译器版本 {0}</target>
Expand Down
Loading