Skip to content

Commit

Permalink
First stab at dotnet#20648
Browse files Browse the repository at this point in the history
  • Loading branch information
gafter committed Jul 6, 2017
1 parent 2738218 commit 64313c4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Symbols/FieldSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ internal FieldSymbol AsMember(NamedTypeSymbol newOwner)
{
Debug.Assert(this.IsDefinition);
Debug.Assert(ReferenceEquals(newOwner.OriginalDefinition, this.ContainingSymbol.OriginalDefinition));
return (newOwner == this.ContainingSymbol) ? this : new SubstitutedFieldSymbol(newOwner as SubstitutedNamedTypeSymbol, this);
return (newOwner == this.ContainingSymbol) ? this : new SubstitutedFieldSymbol(newOwner, this);
}

#region Use-Site Diagnostics
Expand Down
4 changes: 4 additions & 0 deletions src/Compilers/CSharp/Portable/Symbols/NamedTypeSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,10 @@ internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
if (this.Equals(t2, comparison)) return true;
}
}
else
{
if (this.IsTupleType != t2.IsTupleType) return false;
}

NamedTypeSymbol other = t2 as NamedTypeSymbol;
if ((object)other == null) return false;
Expand Down
15 changes: 6 additions & 9 deletions src/Compilers/CSharp/Portable/Symbols/SubstitutedFieldSymbol.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
// 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.CSharp.Emit;
using Roslyn.Utilities;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using Microsoft.CodeAnalysis.CSharp.Emit;
using System.Globalization;

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
internal sealed class SubstitutedFieldSymbol : WrappedFieldSymbol
{
private readonly SubstitutedNamedTypeSymbol _containingType;
private readonly NamedTypeSymbol _containingType;
private TypeSymbol _lazyType;

internal SubstitutedFieldSymbol(SubstitutedNamedTypeSymbol containingType, FieldSymbol substitutedFrom)
internal SubstitutedFieldSymbol(NamedTypeSymbol containingType, FieldSymbol substitutedFrom)
: base((FieldSymbol)substitutedFrom.OriginalDefinition)
{
Debug.Assert(containingType.TypeSubstitution != null);
_containingType = containingType;
}

Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Symbols/Symbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ internal static ImmutableArray<SyntaxReference> GetDeclaringSyntaxReferenceHelpe
/// the "value" parameter for a property setter,
/// the parameters on indexer accessor methods (not on the indexer itself),
/// methods in anonymous types,
/// tuple types,
/// </summary>
public virtual bool IsImplicitlyDeclared
{
Expand Down
33 changes: 27 additions & 6 deletions src/Compilers/CSharp/Portable/Symbols/Tuples/TupleTypeSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,11 @@ public override Symbol ContainingSymbol
}
}

/// <summary>
/// The locations in source where the tuple type originated. Note that, unlike for most
/// other constructed types, this differs from the locations of the underlying type that
/// the tuple type was constructed from.
/// </summary>
public override ImmutableArray<Location> Locations
{
get
Expand Down Expand Up @@ -1266,44 +1271,60 @@ public override int Arity
{
get
{
return 0;
return _underlyingType.Arity;
}
}

public override ImmutableArray<TypeParameterSymbol> TypeParameters
{
get
{
return ImmutableArray<TypeParameterSymbol>.Empty;
return _underlyingType.TypeParameters;
}
}

internal override TypeMap TypeSubstitution
{
get
{
return _underlyingType.TypeSubstitution;
}
}

public override ImmutableArray<CustomModifier> GetTypeArgumentCustomModifiers(int ordinal)
{
return GetEmptyTypeArgumentCustomModifiers(ordinal);
return _underlyingType.GetTypeArgumentCustomModifiers(ordinal);
}

internal override bool HasTypeArgumentsCustomModifiers
{
get
{
return false;
return _underlyingType.HasTypeArgumentsCustomModifiers;
}
}

internal override ImmutableArray<TypeSymbol> TypeArgumentsNoUseSiteDiagnostics
{
get
{
return ImmutableArray<TypeSymbol>.Empty;
return _underlyingType.TypeArgumentsNoUseSiteDiagnostics;
}
}

public override NamedTypeSymbol ConstructedFrom
{
get
{
return this;
return _underlyingType.ConstructedFrom;
}
}

public override NamedTypeSymbol OriginalDefinition
{
get
{
return _underlyingType.OriginalDefinition;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11344,8 +11344,10 @@ static void Main()
Assert.False(m1Tuple.IsImplicitlyDeclared);
Assert.True(m1Tuple.IsTupleType);
Assert.Equal("System.ValueTuple<System.Int32, System.Int32>", m1Tuple.TupleUnderlyingType.ToTestDisplayString());
Assert.Same(m1Tuple, m1Tuple.ConstructedFrom);
Assert.Same(m1Tuple, m1Tuple.OriginalDefinition);
Assert.NotSame(m1Tuple, m1Tuple.ConstructedFrom);
Assert.Same(m1Tuple.ConstructedFrom, m1Tuple.TupleUnderlyingType.ConstructedFrom);
Assert.NotSame(m1Tuple, m1Tuple.OriginalDefinition);
Assert.Same(m1Tuple.OriginalDefinition, m1Tuple.TupleUnderlyingType.OriginalDefinition);
AssertTupleTypeEquality(m1Tuple);
Assert.Same(m1Tuple.TupleUnderlyingType.ContainingSymbol, m1Tuple.ContainingSymbol);
Assert.Null(m1Tuple.GetUseSiteDiagnostic());
Expand Down

0 comments on commit 64313c4

Please sign in to comment.