Skip to content

Commit

Permalink
Merge branch 'master' into nullable-states
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Mar 1, 2019
2 parents bfe2e73 + 5d70e9b commit 2b6ee0d
Show file tree
Hide file tree
Showing 40 changed files with 925 additions and 1,206 deletions.
6 changes: 3 additions & 3 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@
<UsingToolXliff>true</UsingToolXliff>
<UsingToolXUnit>true</UsingToolXUnit>
<!--
During the transition period from Microsoft.Net.Compilers to Microsoft.Net.Compilers.Toolset
we are always doing custom importing here.
When using a bootstrap builder we don't want to use the Microsoft.Net.Compilers.Toolset package but
rather explicitly override it.
-->
<UsingToolMicrosoftNetCompilers>false</UsingToolMicrosoftNetCompilers>
<UsingToolMicrosoftNetCompilers Condition="'$(BootstrapBuildPath)' == ''">true</UsingToolMicrosoftNetCompilers>
</PropertyGroup>
<PropertyGroup>
<RestoreSources>
Expand Down
8 changes: 0 additions & 8 deletions eng/targets/Settings.props
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@
-->
<Import Project="Bootstrap.props" Condition="'$(BootstrapBuildPath)' != ''" />

<!--
During the transition period from Microsoft.Net.Compilers to Microsoft.Net.Compilers.Toolset
we need our own PackageReference
-->
<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="$(MicrosoftNetCompilersToolsetVersion)" Condition="'$(BootstrapBuildPath)' == ''" PrivateAssets="all" IsImplicitlyDefined="true" />
</ItemGroup>

<!--
Analyzers
-->
Expand Down
109 changes: 66 additions & 43 deletions src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,43 @@ private BoundExpression BindRangeExpression(RangeExpressionSyntax node, Diagnost

if (!rangeType.IsErrorType())
{
symbolOpt = (MethodSymbol)GetWellKnownTypeMember(Compilation, WellKnownMember.System_Range__ctor, diagnostics, syntax: node);
// Depending on the available arguments to the range expression, there are four
// possible well-known members we could bind to. The constructor is always the
// fallback member, usable in any situation. However, if any of the other members
// are available and applicable, we will prefer that.

WellKnownMember? memberOpt = null;
if (node.LeftOperand is null && node.RightOperand is null)
{
memberOpt = WellKnownMember.System_Range__get_All;
}
else if (node.LeftOperand is null)
{
memberOpt = WellKnownMember.System_Range__EndAt;
}
else if (node.RightOperand is null)
{
memberOpt = WellKnownMember.System_Range__StartAt;
}

if (!(memberOpt is null))
{
symbolOpt = (MethodSymbol)GetWellKnownTypeMember(
Compilation,
memberOpt.GetValueOrDefault(),
diagnostics,
syntax: node,
isOptional: true);
}

if (symbolOpt is null)
{
symbolOpt = (MethodSymbol)GetWellKnownTypeMember(
Compilation,
WellKnownMember.System_Range__ctor,
diagnostics,
syntax: node);
}
}

BoundExpression left = BindRangeExpressionOperand(node.LeftOperand, diagnostics);
Expand Down Expand Up @@ -6864,8 +6900,11 @@ private BoundExpression BindArrayAccess(ExpressionSyntax node, BoundExpression e
}
}

var resultType = rank == 1 &&
TypeSymbol.Equals(convertedArguments[0].Type, Compilation.GetWellKnownType(WellKnownType.System_Range), TypeCompareKind.ConsiderEverything2)
TypeSymbol resultType = rank == 1 &&
TypeSymbol.Equals(
convertedArguments[0].Type,
Compilation.GetWellKnownType(WellKnownType.System_Range),
TypeCompareKind.ConsiderEverything)
? arrayType
: arrayType.ElementType.TypeSymbol;

Expand Down Expand Up @@ -6893,9 +6932,30 @@ private BoundExpression ConvertToArrayIndex(BoundExpression index, SyntaxNode no

if (result is null && allowIndexAndRange)
{
result =
TryImplicitConversionToArrayIndex(index, WellKnownType.System_Index, node, diagnostics) ??
TryImplicitConversionToArrayIndex(index, WellKnownType.System_Range, node, diagnostics);
result = TryImplicitConversionToArrayIndex(index, WellKnownType.System_Index, node, diagnostics);

if (result is null)
{
result = TryImplicitConversionToArrayIndex(index, WellKnownType.System_Range, node, diagnostics);
if (!(result is null))
{
// This member is needed for lowering and should produce an error if not present
_ = GetWellKnownTypeMember(
Compilation,
WellKnownMember.System_Runtime_CompilerServices_RuntimeHelpers__GetSubArray_T,
diagnostics,
syntax: node);
}
}
else
{
// This member is needed for lowering and should produce an error if not present
_ = GetWellKnownTypeMember(
Compilation,
WellKnownMember.System_Index__GetOffset,
diagnostics,
syntax: node);
}
}

if (result is null)
Expand Down Expand Up @@ -7216,43 +7276,6 @@ private BoundExpression BindIndexerOrIndexedPropertyAccess(

if (!analyzedArguments.HasErrors)
{
// https://github.com/dotnet/roslyn/issues/30620
// Pretend like there are indexers that support range and index
if (receiverOpt?.Type.SpecialType == SpecialType.System_String &&
analyzedArguments.Arguments.Count == 1)
{
var argType = analyzedArguments.Arguments[0].Type;
TypeSymbol resultType = null;
if (TypeSymbol.Equals(argType, Compilation.GetWellKnownType(WellKnownType.System_Index), TypeCompareKind.ConsiderEverything2))
{
resultType = GetSpecialType(SpecialType.System_Char, diagnostics, syntax);
}
else if (TypeSymbol.Equals(argType, Compilation.GetWellKnownType(WellKnownType.System_Range), TypeCompareKind.ConsiderEverything2))
{
resultType = GetSpecialType(SpecialType.System_String, diagnostics, syntax);
}

if (!(resultType is null))
{
var args = analyzedArguments.Arguments.ToImmutable();

overloadResolutionResult.Free();
return new BoundIndexerAccess(
syntax,
receiverOpt,
candidates[0],
args,
argumentNames,
argumentRefKinds,
expanded: false,
argsToParamsOpt: default,
binderOpt: this,
useSetterForDefaultArgumentGeneration: false,
resultType,
hasErrors: false);
}
}

// Dev10 uses the "this" keyword as the method name for indexers.
var candidate = candidates[0];
var name = candidate.IsIndexer ? SyntaxFacts.GetText(SyntaxKind.ThisKeyword) : candidate.Name;
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@
<!-- Non-null type is required for this node kind -->
<Field Name="Type" Type="TypeSymbol" Override="true" Null="disallow"/>

<Field Name="LeftOperand" Type="BoundExpression" Null="allow"/>
<Field Name="RightOperand" Type="BoundExpression" Null="allow"/>
<Field Name="LeftOperandOpt" Type="BoundExpression" Null="allow"/>
<Field Name="RightOperandOpt" Type="BoundExpression" Null="allow"/>
<Field Name="MethodOpt" Type="MethodSymbol" Null="allow"/>
</Node>

Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@
<value>A params parameter must be the last parameter in a formal parameter list</value>
</data>
<data name="ERR_SizeofUnsafe" xml:space="preserve">
<value>'{0}' does not have a predefined size, therefore sizeof can only be used in an unsafe context (consider using System.Runtime.InteropServices.Marshal.SizeOf)</value>
<value>'{0}' does not have a predefined size, therefore sizeof can only be used in an unsafe context</value>
</data>
<data name="ERR_DottedTypeNameNotFoundInNS" xml:space="preserve">
<value>The type or namespace name '{0}' does not exist in the namespace '{1}' (are you missing an assembly reference?)</value>
Expand Down Expand Up @@ -5796,4 +5796,4 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_FeatureInPreview" xml:space="preserve">
<value>The feature '{0}' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2099,14 +2099,14 @@ public override BoundNode VisitUnaryOperator(BoundUnaryOperator node)

public override BoundNode VisitRangeExpression(BoundRangeExpression node)
{
if (node.LeftOperand != null)
if (node.LeftOperandOpt != null)
{
VisitRvalue(node.LeftOperand);
VisitRvalue(node.LeftOperandOpt);
}

if (node.RightOperand != null)
if (node.RightOperandOpt != null)
{
VisitRvalue(node.RightOperand);
VisitRvalue(node.RightOperandOpt);
}

return null;
Expand Down
14 changes: 1 addition & 13 deletions src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4651,19 +4651,7 @@ private void VisitIndexerAccess(BoundIndexerAccess node, out PropertySymbol inde

VisitArguments(node, node.Arguments, node.ArgumentRefKindsOpt, node.Indexer, node.ArgsToParamsOpt, node.Expanded);

// https://github.com/dotnet/roslyn/issues/30620 remove before shipping dev16
TypeWithState type;
if (node.Arguments.Length == 1 &&
TypeSymbol.Equals(node.Arguments[0].Type, compilation.GetWellKnownType(WellKnownType.System_Range), TypeCompareKind.ConsiderEverything2))
{
type = new TypeWithState(node.Type, NullableFlowState.NotNull);
}
else
{
type = indexer.Type.ToTypeWithState();
}

SetResult(type, indexer.Type);
LvalueResultType = node.Indexer.Type;
}

public override BoundNode VisitEventAccess(BoundEventAccess node)
Expand Down
34 changes: 17 additions & 17 deletions src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs

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

Loading

0 comments on commit 2b6ee0d

Please sign in to comment.