Skip to content
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 eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<UsingToolXUnit>false</UsingToolXUnit>
<UseVSTestRunner>true</UseVSTestRunner>
<!-- Prohibit the usage of .NET Standard 1.x dependencies. -->
<FlagNetStandard1XDependencies Condition="'$(DotNetBuildSourceOnly)' == 'true' and '$(DotNetBuildOrchestrator)' == 'true'">true</FlagNetStandard1XDependencies>
<FlagNetStandard1XDependencies Condition="'$(DotNetBuildSourceOnly)' == 'true' and '$(DotNetBuildFromVMR)' == 'true'">true</FlagNetStandard1XDependencies>
</PropertyGroup>
<PropertyGroup>
<!--
Expand Down
3 changes: 0 additions & 3 deletions src/Compilers/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ dotnet_diagnostic.RS0100.severity = none
# RS0102: Braces must not have blank lines between them
dotnet_diagnostic.RS0102.severity = none

# IDE0051: Unused member
dotnet_diagnostic.IDE0051.severity = none

# IDE0170: Prefer extended property pattern
dotnet_diagnostic.IDE0170.severity = suggestion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;
Expand Down Expand Up @@ -282,7 +284,22 @@ internal sealed override CommandLineArguments CommonParse(IEnumerable<string> ar

#if DEBUG
case "attachdebugger":
Debugger.Launch();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Debugger.Launch() only works on Windows.
_ = Debugger.Launch();
}
else
{
var timeout = TimeSpan.FromMinutes(2);
Console.WriteLine($"Compiler started with process ID {Environment.ProcessId}");
Console.WriteLine($"Waiting {timeout:g} for a debugger to attach");
using var timeoutSource = new CancellationTokenSource(timeout);
while (!Debugger.IsAttached && !timeoutSource.Token.IsCancellationRequested)
{
Thread.Sleep(100);
}
}
continue;
#endif
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace Microsoft.CodeAnalysis.CSharp;

internal static class EnvironmentExtensions
{
extension(Environment)
{
public static int ProcessId
{
get
{
#if NET
return Environment.ProcessId;
#else
return System.Diagnostics.Process.GetCurrentProcess().Id;
#endif
}
}
}
}
78 changes: 78 additions & 0 deletions src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37623,6 +37623,84 @@ public void M() { }
comp.VerifyDiagnostics();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79309")]
public void FunctionType_InstanceReceiver_12()
{
// static non-extension method vs. extension property
var src = """
var x = new C().M;

public static class E
{
extension(C c)
{
public int M => 42;
}
}

public class C
{
public static int M() => throw null;
}
""";
var comp = CreateCompilation(src);
comp.VerifyEmitDiagnostics(
// (1,9): error CS8917: The delegate type could not be inferred.
// var x = new C().M;
Diagnostic(ErrorCode.ERR_CannotInferDelegateType, "new C().M").WithLocation(1, 9));

var tree = comp.SyntaxTrees.First();
var model = comp.GetSemanticModel(tree);
var localDeclaration = GetSyntax<VariableDeclarationSyntax>(tree, "var x = new C().M");
Assert.Equal("?", model.GetTypeInfo(localDeclaration.Type).Type.ToTestDisplayString());

// without non-extension method
src = """
var x = new C().M;
System.Console.Write(x);

public static class E
{
extension(C c)
{
public int M => 42;
}
}

public class C
{
}
""";
comp = CreateCompilation(src);
CompileAndVerify(comp, expectedOutput: "42").VerifyDiagnostics();

tree = comp.SyntaxTrees.First();
model = comp.GetSemanticModel(tree);
localDeclaration = GetSyntax<VariableDeclarationSyntax>(tree, "var x = new C().M");
Assert.Equal("System.Int32", model.GetTypeInfo(localDeclaration.Type).Type.ToTestDisplayString());

// analogous non-extension scenario
src = """
var x = new C().M;
System.Console.Write(x);

public class Base
{
public int M => 42;
}

public class C : Base
{
public static new int M() => throw null;
}
""";
comp = CreateCompilation(src);
comp.VerifyEmitDiagnostics(
// (1,9): error CS8917: The delegate type could not be inferred.
// var x = new C().M;
Diagnostic(ErrorCode.ERR_CannotInferDelegateType, "new C().M").WithLocation(1, 9));
}

[Fact]
public void FunctionType_ColorColorReceiver_01()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Security.Cryptography
Imports System.Text
Imports System.Threading
Imports Microsoft.CodeAnalysis.Collections
Imports Microsoft.CodeAnalysis.Emit
Imports Microsoft.CodeAnalysis.PooledObjects
Expand Down Expand Up @@ -446,7 +447,24 @@ Namespace Microsoft.CodeAnalysis.VisualBasic

#If DEBUG Then
Case "attachdebugger"
Debugger.Launch()
If RuntimeInformation.IsOSPlatform(OSPlatform.Windows) Then
' Debugger.Launch() only works on Windows
Debugger.Launch()
Else
Dim timeout = TimeSpan.FromMinutes(2)
#If NET Then
Dim processId = Environment.ProcessId
#Else
Dim processId = System.Diagnostics.Process.GetCurrentProcess().Id
#End If
Console.WriteLine($"Compiler started with process ID {processId}")
Console.WriteLine($"Waiting {timeout:g} for a debugger to attach")
Using timeoutSource = New CancellationTokenSource(timeout)
While Not Debugger.IsAttached AndAlso Not timeoutSource.Token.IsCancellationRequested
Thread.Sleep(100)
End While
End Using
End If
Continue For
#End If
End Select
Expand Down
Loading