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

Merge release/dev17.1 to release/dev17.1-vs-deps #59155

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
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,10 @@ private Conversion ClassifyStandardImplicitConversion(BoundExpression sourceExpr
//
// We extend the definition of standard implicit conversions to include
// all of the implicit conversions that are allowed based on an expression,
// with the exception of the switch expression conversion and the interpolated
// string builder conversion.
// with the exception of the switch expression conversion.

Conversion conversion = ClassifyImplicitBuiltInConversionFromExpression(sourceExpression, source, destination, ref useSiteInfo);
if (conversion.Exists && !conversion.IsInterpolatedStringHandler)
if (conversion.Exists)
{
Debug.Assert(IsStandardImplicitConversionFromExpression(conversion.Kind));
return conversion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ private static bool IsEncompassingImplicitConversionKind(ConversionKind kind)
case ConversionKind.ImplicitEnumeration:
case ConversionKind.StackAllocToPointerType:
case ConversionKind.StackAllocToSpanType:
case ConversionKind.InterpolatedStringHandler:

// Not "standard".
case ConversionKind.ImplicitUserDefined:
Expand Down Expand Up @@ -647,9 +646,6 @@ private static bool IsEncompassingImplicitConversionKind(ConversionKind kind)

// Added for C# 7.1
case ConversionKind.DefaultLiteral:

// Added for C# 9
case ConversionKind.ImplicitPointer:
return true;

default:
Expand Down
188 changes: 1 addition & 187 deletions src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ struct S {}");
}

[Fact]
public void UserDefinedConversion_01()
public void UserDefinedConversion()
{
var comp = CreateCompilationWithFunctionPointers(@"
unsafe class C
Expand Down Expand Up @@ -513,192 +513,6 @@ .maxstack 1
}
}

[Fact, WorkItem(57994, "https://github.com/dotnet/roslyn/issues/57994")]
public void UserDefinedConversion_02()
{
var comp = CreateCompilationWithFunctionPointers(@"
unsafe readonly struct S
{
public static implicit operator delegate*<void*, void>(S _) => null;
void M()
{
// S -> delegate*<void*, void> -> delegate*<int*, void>
/*<bind>*/_ = (delegate*<int*, void>)new S()/*</bind>*/;
}
}");

var verifier = CompileAndVerifyFunctionPointers(comp);
verifier.VerifyIL("S.M", @"
{
// Code size 16 (0x10)
.maxstack 1
.locals init (S V_0)
IL_0000: ldloca.s V_0
IL_0002: initobj ""S""
IL_0008: ldloc.0
IL_0009: call ""delegate*<void*, void> S.op_Implicit(S)""
IL_000e: pop
IL_000f: ret
}
");

VerifyOperationTreeForTest<AssignmentExpressionSyntax>(comp, @"
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: delegate*<System.Int32*, System.Void>) (Syntax: '_ = (delega ... id>)new S()')
Left:
IDiscardOperation (Symbol: delegate*<System.Int32*, System.Void> _) (OperationKind.Discard, Type: delegate*<System.Int32*, System.Void>) (Syntax: '_')
Right:
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: delegate*<System.Int32*, System.Void>, IsImplicit) (Syntax: '(delegate*< ... id>)new S()')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
IConversionOperation (TryCast: False, Unchecked) (OperatorMethod: delegate*<System.Void*, System.Void> S.op_Implicit(S _)) (OperationKind.Conversion, Type: delegate*<System.Void*, System.Void>, IsImplicit) (Syntax: '(delegate*< ... id>)new S()')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: True) (MethodSymbol: delegate*<System.Void*, System.Void> S.op_Implicit(S _))
Operand:
IObjectCreationOperation (Constructor: S..ctor()) (OperationKind.ObjectCreation, Type: S) (Syntax: 'new S()')
Arguments(0)
Initializer:
null
");
}

[Fact, WorkItem(57994, "https://github.com/dotnet/roslyn/issues/57994")]
public void UserDefinedConversion_03()
{
var comp = CreateCompilationWithFunctionPointers(@"
unsafe readonly struct S
{
public static explicit operator delegate*<void*, void>(S _) => null;
void M()
{
// S -> delegate*<void*, void> -> delegate*<int*, void>
/*<bind>*/_ = (delegate*<int*, void>)new S()/*</bind>*/;
}
}");

var verifier = CompileAndVerifyFunctionPointers(comp);
verifier.VerifyIL("S.M", @"
{
// Code size 16 (0x10)
.maxstack 1
.locals init (S V_0)
IL_0000: ldloca.s V_0
IL_0002: initobj ""S""
IL_0008: ldloc.0
IL_0009: call ""delegate*<void*, void> S.op_Explicit(S)""
IL_000e: pop
IL_000f: ret
}
");

VerifyOperationTreeForTest<AssignmentExpressionSyntax>(comp, @"
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: delegate*<System.Int32*, System.Void>) (Syntax: '_ = (delega ... id>)new S()')
Left:
IDiscardOperation (Symbol: delegate*<System.Int32*, System.Void> _) (OperationKind.Discard, Type: delegate*<System.Int32*, System.Void>) (Syntax: '_')
Right:
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: delegate*<System.Int32*, System.Void>, IsImplicit) (Syntax: '(delegate*< ... id>)new S()')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
IConversionOperation (TryCast: False, Unchecked) (OperatorMethod: delegate*<System.Void*, System.Void> S.op_Explicit(S _)) (OperationKind.Conversion, Type: delegate*<System.Void*, System.Void>, IsImplicit) (Syntax: '(delegate*< ... id>)new S()')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: True) (MethodSymbol: delegate*<System.Void*, System.Void> S.op_Explicit(S _))
Operand:
IObjectCreationOperation (Constructor: S..ctor()) (OperationKind.ObjectCreation, Type: S) (Syntax: 'new S()')
Arguments(0)
Initializer:
null
");
}

[Fact, WorkItem(57994, "https://github.com/dotnet/roslyn/issues/57994")]
public void UserDefinedConversion_04()
{
var comp = CreateCompilationWithFunctionPointers(@"
unsafe readonly struct S
{
public static implicit operator delegate*<void*, void>(S _) => null;
void M()
{
// S -> delegate*<void*, void> -> delegate*<int*, void>
/*<bind>*/delegate*<int*, void> _ = new S()/*</bind>*/;
}
}");

var verifier = CompileAndVerifyFunctionPointers(comp);
verifier.VerifyIL("S.M", @"
{
// Code size 16 (0x10)
.maxstack 1
.locals init (delegate*<int*, void> V_0, //_
S V_1)
IL_0000: ldloca.s V_1
IL_0002: initobj ""S""
IL_0008: ldloc.1
IL_0009: call ""delegate*<void*, void> S.op_Implicit(S)""
IL_000e: stloc.0
IL_000f: ret
}
");

VerifyOperationTreeForTest<VariableDeclarationSyntax>(comp, @"
IVariableDeclarationOperation (1 declarators) (OperationKind.VariableDeclaration, Type: null) (Syntax: 'delegate*<i ... _ = new S()')
Declarators:
IVariableDeclaratorOperation (Symbol: delegate*<System.Int32*, System.Void> _) (OperationKind.VariableDeclarator, Type: null) (Syntax: '_ = new S()')
Initializer:
IVariableInitializerOperation (OperationKind.VariableInitializer, Type: null) (Syntax: '= new S()')
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: delegate*<System.Int32*, System.Void>, IsImplicit) (Syntax: 'new S()')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
IConversionOperation (TryCast: False, Unchecked) (OperatorMethod: delegate*<System.Void*, System.Void> S.op_Implicit(S _)) (OperationKind.Conversion, Type: delegate*<System.Void*, System.Void>, IsImplicit) (Syntax: 'new S()')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: True) (MethodSymbol: delegate*<System.Void*, System.Void> S.op_Implicit(S _))
Operand:
IObjectCreationOperation (Constructor: S..ctor()) (OperationKind.ObjectCreation, Type: S) (Syntax: 'new S()')
Arguments(0)
Initializer:
null
Initializer:
null
");
}

[Fact, WorkItem(57994, "https://github.com/dotnet/roslyn/issues/57994")]
public void UserDefinedConversion_05()
{
var comp = CreateCompilationWithFunctionPointers(@"
unsafe readonly struct S
{
public static explicit operator delegate*<void*, void>(S _) => null;
void M()
{
// S -> delegate*<void*, void> -> delegate*<int*, void>
/*<bind>*/delegate*<int*, void> _ = new S()/*</bind>*/;
}
}");

comp.VerifyDiagnostics(
// (8,45): error CS0266: Cannot implicitly convert type 'S' to 'delegate*<int*, void>'. An explicit conversion exists (are you missing a cast?)
// /*<bind>*/delegate*<int*, void> _ = new S()/*</bind>*/;
Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "new S()").WithArguments("S", "delegate*<int*, void>").WithLocation(8, 45)
);

VerifyOperationTreeForTest<VariableDeclarationSyntax>(comp, @"
IVariableDeclarationOperation (1 declarators) (OperationKind.VariableDeclaration, Type: null, IsInvalid) (Syntax: 'delegate*<i ... _ = new S()')
Declarators:
IVariableDeclaratorOperation (Symbol: delegate*<System.Int32*, System.Void> _) (OperationKind.VariableDeclarator, Type: null, IsInvalid) (Syntax: '_ = new S()')
Initializer:
IVariableInitializerOperation (OperationKind.VariableInitializer, Type: null, IsInvalid) (Syntax: '= new S()')
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: delegate*<System.Int32*, System.Void>, IsInvalid, IsImplicit) (Syntax: 'new S()')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
IConversionOperation (TryCast: False, Unchecked) (OperatorMethod: delegate*<System.Void*, System.Void> S.op_Explicit(S _)) (OperationKind.Conversion, Type: delegate*<System.Void*, System.Void>, IsInvalid, IsImplicit) (Syntax: 'new S()')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: True) (MethodSymbol: delegate*<System.Void*, System.Void> S.op_Explicit(S _))
Operand:
IObjectCreationOperation (Constructor: S..ctor()) (OperationKind.ObjectCreation, Type: S, IsInvalid) (Syntax: 'new S()')
Arguments(0)
Initializer:
null
Initializer:
null
");
}

[Fact]
public void FunctionPointerToFunctionPointerValid_ReferenceVarianceAndIdentity()
{
Expand Down
135 changes: 0 additions & 135 deletions src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3978,141 +3978,6 @@ public DefaultInterpolatedStringHandler(int literalLength, int formattedCount)
);
}

[Fact, WorkItem(58346, "https://github.com/dotnet/roslyn/issues/58346")]
public void UserDefinedConversion_AsFromTypeOfConversion_01()
{
var code = @"
struct S
{
public static implicit operator S(CustomHandler c) => default;

static void M()
{
/*<bind>*/S s = $"""";/*</bind>*/
}
}
";

var handler = GetInterpolatedStringCustomHandlerType("CustomHandler", "struct", useBoolReturns: false);

var comp = CreateCompilation(new[] { code, handler });
comp.VerifyDiagnostics(
// (8,25): error CS0029: Cannot implicitly convert type 'string' to 'S'
// /*<bind>*/S s = $"";/*<bind>*/
Diagnostic(ErrorCode.ERR_NoImplicitConv, @"$""""").WithArguments("string", "S").WithLocation(8, 25)
);

VerifyOperationTreeForTest<LocalDeclarationStatementSyntax>(comp, @"
IVariableDeclarationGroupOperation (1 declarations) (OperationKind.VariableDeclarationGroup, Type: null, IsInvalid) (Syntax: 'S s = $"""";')
IVariableDeclarationOperation (1 declarators) (OperationKind.VariableDeclaration, Type: null, IsInvalid) (Syntax: 'S s = $""""')
Declarators:
IVariableDeclaratorOperation (Symbol: S s) (OperationKind.VariableDeclarator, Type: null, IsInvalid) (Syntax: 's = $""""')
Initializer:
IVariableInitializerOperation (OperationKind.VariableInitializer, Type: null, IsInvalid) (Syntax: '= $""""')
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: S, IsInvalid, IsImplicit) (Syntax: '$""""')
Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
IInterpolatedStringOperation (OperationKind.InterpolatedString, Type: System.String, Constant: """", IsInvalid) (Syntax: '$""""')
Parts(0)
Initializer:
null
");
}

[Fact, WorkItem(58346, "https://github.com/dotnet/roslyn/issues/58346")]
public void UserDefinedConversion_AsFromTypeOfConversion_02()
{
var code = @"
struct S
{
public static implicit operator S(CustomHandler c) => default;

static void M()
{
/*<bind>*/S s = (S)$"""";/*</bind>*/
}
}
";

var handler = GetInterpolatedStringCustomHandlerType("CustomHandler", "struct", useBoolReturns: false);

var comp = CreateCompilation(new[] { code, handler });
comp.VerifyDiagnostics(
// (8,25): error CS0030: Cannot convert type 'string' to 'S'
// /*<bind>*/S s = (S)$"";/*<bind>*/
Diagnostic(ErrorCode.ERR_NoExplicitConv, @"(S)$""""").WithArguments("string", "S").WithLocation(8, 25)
);

VerifyOperationTreeForTest<LocalDeclarationStatementSyntax>(comp, @"
IVariableDeclarationGroupOperation (1 declarations) (OperationKind.VariableDeclarationGroup, Type: null, IsInvalid) (Syntax: 'S s = (S)$"""";')
IVariableDeclarationOperation (1 declarators) (OperationKind.VariableDeclaration, Type: null, IsInvalid) (Syntax: 'S s = (S)$""""')
Declarators:
IVariableDeclaratorOperation (Symbol: S s) (OperationKind.VariableDeclarator, Type: null, IsInvalid) (Syntax: 's = (S)$""""')
Initializer:
IVariableInitializerOperation (OperationKind.VariableInitializer, Type: null, IsInvalid) (Syntax: '= (S)$""""')
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: S, IsInvalid) (Syntax: '(S)$""""')
Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
IInterpolatedStringOperation (OperationKind.InterpolatedString, Type: System.String, Constant: """", IsInvalid) (Syntax: '$""""')
Parts(0)
Initializer:
null
");
}

[Fact, WorkItem(58346, "https://github.com/dotnet/roslyn/issues/58346")]
public void UserDefinedConversion_AsFromTypeOfConversion_03()
{
var code = @"
/*<bind>*/S s = (CustomHandler)$"""";/*</bind>*/

struct S
{
public static implicit operator S(CustomHandler c)
{
System.Console.WriteLine(""In handler"");
return default;
}
}
";

var handler = GetInterpolatedStringCustomHandlerType("CustomHandler", "struct", useBoolReturns: false);

var comp = CreateCompilation(new[] { code, handler });
CompileAndVerify(comp, expectedOutput: "In handler").VerifyDiagnostics();

VerifyOperationTreeForTest<LocalDeclarationStatementSyntax>(comp, @"
IVariableDeclarationGroupOperation (1 declarations) (OperationKind.VariableDeclarationGroup, Type: null) (Syntax: 'S s = (Cust ... andler)$"""";')
IVariableDeclarationOperation (1 declarators) (OperationKind.VariableDeclaration, Type: null) (Syntax: 'S s = (CustomHandler)$""""')
Declarators:
IVariableDeclaratorOperation (Symbol: S s) (OperationKind.VariableDeclarator, Type: null) (Syntax: 's = (CustomHandler)$""""')
Initializer:
IVariableInitializerOperation (OperationKind.VariableInitializer, Type: null) (Syntax: '= (CustomHandler)$""""')
IConversionOperation (TryCast: False, Unchecked) (OperatorMethod: S S.op_Implicit(CustomHandler c)) (OperationKind.Conversion, Type: S, IsImplicit) (Syntax: '(CustomHandler)$""""')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: True) (MethodSymbol: S S.op_Implicit(CustomHandler c))
Operand:
IInterpolatedStringHandlerCreationOperation (HandlerAppendCallsReturnBool: False, HandlerCreationHasSuccessParameter: False) (OperationKind.InterpolatedStringHandlerCreation, Type: CustomHandler) (Syntax: '(CustomHandler)$""""')
Creation:
IObjectCreationOperation (Constructor: CustomHandler..ctor(System.Int32 literalLength, System.Int32 formattedCount)) (OperationKind.ObjectCreation, Type: CustomHandler, IsImplicit) (Syntax: '$""""')
Arguments(2):
IArgumentOperation (ArgumentKind.Explicit, Matching Parameter: literalLength) (OperationKind.Argument, Type: null, IsImplicit) (Syntax: '$""""')
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 0, IsImplicit) (Syntax: '$""""')
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
IArgumentOperation (ArgumentKind.Explicit, Matching Parameter: formattedCount) (OperationKind.Argument, Type: null, IsImplicit) (Syntax: '$""""')
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 0, IsImplicit) (Syntax: '$""""')
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Initializer:
null
Content:
IInterpolatedStringOperation (OperationKind.InterpolatedString, Type: System.String, Constant: """") (Syntax: '$""""')
Parts(0)
Initializer:
null
");
}

[Theory]
[InlineData(@"$""Text{1}""")]
[InlineData(@"$""Text"" + $""{1}""")]
Expand Down
Loading