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

Update usage string for VBC and update checklist for new LangVersion #19113

Merged
merged 7 commits into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -4467,7 +4467,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
/define:<symbol list> Define conditional compilation symbol(s) (Short
form: /d)
/langversion:<string> Specify language version mode: ISO-1, ISO-2, 3,
4, 5, 6, Default, or Latest
4, 5, 6, 7, 7.1, Default, or Latest

- SECURITY -
/delaysign[+|-] Delay-sign the assembly using only the public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ internal sealed class TupleTypeSymbol : WrappedNamedTypeSymbol
internal const string RestFieldName = "Rest";

private TupleTypeSymbol(Location locationOpt, NamedTypeSymbol underlyingType, ImmutableArray<Location> elementLocations,
ImmutableArray<string> elementNames, ImmutableArray<TypeSymbol> elementTypes, ImmutableArray<bool> inferredNamesPositions)
ImmutableArray<string> elementNames, ImmutableArray<TypeSymbol> elementTypes, ImmutableArray<bool> errorPositions)
: this(locationOpt == null ? ImmutableArray<Location>.Empty : ImmutableArray.Create(locationOpt),
underlyingType, elementLocations, elementNames, elementTypes, inferredNamesPositions)
underlyingType, elementLocations, elementNames, elementTypes, errorPositions)
{
}

Expand Down
26 changes: 26 additions & 0 deletions src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,32 @@ public void LanguageVersion_TryParseDisplayString(string input, bool success, La
LanguageVersionAdded_Canary();
}

[Fact]
public void LanguageVersion_CommandLineUsage()
{
var expected = Enum.GetValues(typeof(LanguageVersion)).Cast<LanguageVersion>()
.Where(v => v != LanguageVersion.CSharp1 && v != LanguageVersion.CSharp2)
.Select(v => v.ToDisplayString());
string help = CSharpResources.IDS_CSCHelp;

var rangeStart = help.IndexOf("/langversion");
var rangeEnd = help.IndexOf("/delaysign");
Assert.True(rangeEnd > rangeStart);

string helpRange = help.Substring(rangeStart, rangeEnd - rangeStart).ToLowerInvariant();
var acceptableSurroundingChar = new[] { '\r', '\n', ',' , ' '};
foreach (var version in expected)
{
var foundIndex = helpRange.IndexOf(version);
Assert.True(foundIndex > 0, $"Missing version '{version}'");
Assert.True(Array.IndexOf(acceptableSurroundingChar, helpRange[foundIndex - 1]) >= 0);
Assert.True(Array.IndexOf(acceptableSurroundingChar, helpRange[foundIndex + version.Length]) >= 0);
}

// The canary check is a reminder that this test needs to be updated when a language version is added
LanguageVersionAdded_Canary();
}

[Fact]
[WorkItem(546961, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546961")]
public void Define()
Expand Down
3 changes: 2 additions & 1 deletion src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3838,7 +3838,8 @@ int M()
var model = compilation.GetSemanticModel(tree);
var nodes = tree.GetCompilationUnitRoot().DescendantNodes();

// PROTOTYPE(tuple-names) The type for int? was not picked up
// The type for int? was not picked up
// Follow-up issue: https://github.com/dotnet/roslyn/issues/19144
var yTuple = nodes.OfType<TupleExpressionSyntax>().ElementAt(0);
Assert.Equal("(? e, (System.Int32 e, System.Int32, System.Int32, System.Int32))",
model.GetTypeInfo(yTuple).Type.ToTestDisplayString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Friend Class TupleFieldSymbol
Inherits WrappedFieldSymbol

Protected _containingTuple As TupleTypeSymbol
Protected ReadOnly _containingTuple As TupleTypeSymbol

''' <summary>
''' If this field represents a tuple element with index X, the field contains
''' 2X if this field represents a Default-named element
''' 2X + 1 if this field represents a Friendly-named element
''' Otherwise, (-1 - [index in members array]);
''' </summary>
Private _tupleElementIndex As Integer
Private ReadOnly _tupleElementIndex As Integer

Public Overrides ReadOnly Property IsTupleField As Boolean
Get
Expand Down Expand Up @@ -123,7 +123,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Friend Class TupleElementFieldSymbol
Inherits TupleFieldSymbol

Private _locations As ImmutableArray(Of Location)
Private ReadOnly _locations As ImmutableArray(Of Location)

' default tuple elements like Item1 Or Item20 could be provided by the user or
' otherwise implicitly declared by compiler
Expand Down Expand Up @@ -209,8 +209,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Friend NotInheritable Class TupleVirtualElementFieldSymbol
Inherits TupleElementFieldSymbol

Private _name As String
Private _cannotUse As Boolean ' With LanguageVersion 15, we will produce named elements that should not be used
Private ReadOnly _name As String
Private ReadOnly _cannotUse As Boolean ' With LanguageVersion 15, we will produce named elements that should not be used

Public Sub New(container As TupleTypeSymbol,
underlyingField As FieldSymbol,
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/VisualBasic/Portable/VBResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5130,7 +5130,7 @@
import_list:namespace,...
/langversion:&lt;number&gt; Specify language version:
9|9.0|10|10.0|11|11.0|12|12.0|14|14.0|15|
15.0|default|latest
15.0|15.3|default|latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test that vbc -? contains LanguageVersion.GetErrorName() for each value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test for ToDisplayString.
GetErrorName always includes a decimal, but ToDisplayString uses integral numbers for major versions.
Not sure which is best.

/optionexplicit[+|-] Require explicit declaration of variables.
/optioninfer[+|-] Allow type inference of variables.
/rootnamespace:&lt;string&gt; Specifies the root Namespace for all type
Expand Down
26 changes: 26 additions & 0 deletions src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1616,14 +1616,17 @@ End Module").Path
<Fact>
Public Sub LanguageVersionAdded_Canary()
' When a new version is added, this test will break. This list must be checked:
' - update the command-line error for bad /langver flag (<see cref="ERRID.IDS_VBCHelp"/>)
' - update the "UpgradeProject" codefixer
' - update the IDE drop-down for selecting Language Version
' - update legacy project system to pass Language Version from MSBuild to IDE (see CVbcMSBuildHostObject::SetLanguageVersion)
' - update all the tests that call this canary
' - update the command-line documentation (CommandLine.md)
AssertEx.SetEqual({"default", "9", "10", "11", "12", "14", "15", "15.3", "latest"},
System.Enum.GetValues(GetType(LanguageVersion)).Cast(Of LanguageVersion)().Select(Function(v) v.ToDisplayString()))
' For minor versions, the format should be "x.y", such as "15.3"
End Sub

<Fact>
Public Sub LanguageVersion_GetErrorCode()
Dim versions = System.Enum.GetValues(GetType(LanguageVersion)).
Expand Down Expand Up @@ -1693,6 +1696,29 @@ End Module").Path
LanguageVersionAdded_Canary()
End Sub

<Fact>
Public Sub LanguageVersion_CommandLineUsage()
Dim expected = [Enum].GetValues(GetType(LanguageVersion)).Cast(Of LanguageVersion)().Select(Function(v) v.ToDisplayString())
Dim help = VBResources.IDS_VBCHelp

Dim rangeStart = help.IndexOf("/langversion")
Dim rangeEnd = help.IndexOf("/optionexplicit")
Assert.True(rangeEnd > rangeStart)

Dim helpRange = help.Substring(rangeStart, rangeEnd - rangeStart).ToLowerInvariant()
Dim acceptableSurroundingChar = {CChar(vbCr), CChar(vbLf), "|"c, " "c}

For Each v In expected
Dim foundIndex = helpRange.IndexOf(v)
Assert.True(foundIndex > 0, $"Missing version '{v}'")
Assert.True(Array.IndexOf(acceptableSurroundingChar, helpRange(foundIndex - 1)) >= 0)
Assert.True(Array.IndexOf(acceptableSurroundingChar, helpRange(foundIndex + v.Length)) >= 0)
Next

' The canary check is a reminder that this test needs to be updated when a language version is added
LanguageVersionAdded_Canary()
End Sub

<Fact>
Public Sub TestDefine()
TestDefines({"/D:a=True,b=1", "a.vb"},
Expand Down