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

Wrong error when compiling code containing IEnumerable<Span<T>> #76007

Closed
aannenko opened this issue Nov 21, 2024 · 2 comments
Closed

Wrong error when compiling code containing IEnumerable<Span<T>> #76007

aannenko opened this issue Nov 21, 2024 · 2 comments

Comments

@aannenko
Copy link

aannenko commented Nov 21, 2024

Version Used:
9.0.100

Steps to Reproduce:

  1. dotnet new console
  2. Replace contents of the Program.cs with this:
foreach (var item in IntsAsStrings(5))
    Console.WriteLine(item.ToString());

// intentionally invalid code
static IEnumerable<ReadOnlySpan<char>> IntsAsStrings(int count)
{
    var chars = new char[11];
    for (var i = 0; i < count; i++)
    {
        i.TryFormat(chars, out var charsWritten);
        yield return chars.AsSpan(0, charsWritten);
    }
}
  1. Try compiling it.

Diagnostic Id:

Severity Code Description Project File Line Suppression State
Error (active) MSB6006 "csc.exe" exited with code -2146232797. test C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets 89

Expected Behavior:
Like in .NET 8, we get an appropriate error:

CS9244 The type 'ReadOnlySpan' may not be a ref struct or a type parameter allowing ref structs in order to use it as parameter 'T' in the generic type or method 'IEnumerable'

Actual Behavior:
csc.exe tries and fails to compile the above code.

dotnet build produces the following output:

PS D:\Code\test> dotnet build
Restore complete (0.2s)
  test failed with 58 error(s) (8.0s)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error : Process terminated. System.InvalidOperationException: Unexpected value 'NoConversion' of type 'Microsoft.CodeAnalysis.CSharp.ConversionKind'
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitConversion(BoundConversion conversion)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitConversionExpression(BoundConversion conversion, Boolean used)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitExpressionCoreWithStackGuard(BoundExpression expression, Boolean used)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitExpression(BoundExpression expression, Boolean used)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitReturnStatement(BoundReturnStatement boundReturnStatement)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatements(ImmutableArray`1 statements)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitUninstrumentedBlock(BoundBlock block)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl()
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(PEModuleBuilder moduleBuilder, MethodSymbol method, Int32 methodOrdinal, BoundStatement block, ImmutableArray`1 lambdaDebugInfo, ImmutableArray`1 orderedLambdaRuntimeRudeEdits, ImmutableArray`1 closureDebugInfo, ImmutableArray`1 stateMachineStateDebugInfos, StateMachineTypeSymbol stateMachineTypeOpt, VariableSlotAllocator variableSlotAllocatorOpt, BindingDiagnosticBag diagnostics, DebugDocumentProvider debugDocumentProvider, ImportChain importChainOpt, Boolean emittingPdb, ImmutableArray`1 codeCoverageSpans, AsyncForwardEntryPoint entryPointOpt)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(TypeCompilationState compilationState)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at System.Environment.FailFast(System.Runtime.CompilerServices.StackCrawlMarkHandle, System.String, System.Runtime.CompilerServices.ObjectHandleOnStack, System.String)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at System.Environment.FailFast(System.Threading.StackCrawlMark ByRef, System.String, System.Exception, System.String)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at System.Environment.FailFast(System.String, System.Exception)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.FailFast.OnFatalException(System.Exception)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.ErrorReporting.FatalError.Report(System.Exception, Microsoft.CodeAnalysis.ErrorReporting.ErrorSeverity, Boolean)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.ErrorReporting.FatalError.ReportAndPropagateUnlessCanceled(System.Exception, Microsoft.CodeAnalysis.ErrorReporting.ErrorSeverity)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at System.Runtime.EH.FindFirstPassHandler(System.Object, UInt32, System.Runtime.StackFrameIterator ByRef, UInt32 ByRef, Byte* ByRef)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at System.Runtime.EH.DispatchEx(System.Runtime.StackFrameIterator ByRef, ExInfo ByRef)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at System.Runtime.EH.RhThrowEx(System.Object, ExInfo ByRef)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitConversion(Microsoft.CodeAnalysis.CSharp.BoundConversion)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitConversionExpression(Microsoft.CodeAnalysis.CSharp.BoundConversion, Boolean)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitExpressionCoreWithStackGuard(Microsoft.CodeAnalysis.CSharp.BoundExpression, Boolean)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitExpression(Microsoft.CodeAnalysis.CSharp.BoundExpression, Boolean)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitReturnStatement(Microsoft.CodeAnalysis.CSharp.BoundReturnStatement)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatement(Microsoft.CodeAnalysis.CSharp.BoundStatement)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatements(System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CSharp.BoundStatement>)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitUninstrumentedBlock(Microsoft.CodeAnalysis.CSharp.BoundBlock)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatement(Microsoft.CodeAnalysis.CSharp.BoundStatement)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl()
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(Microsoft.CodeAnalysis.CSharp.Emit.PEModuleBuilder, Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol, Int32, Microsoft.CodeAnalysis.CSharp.BoundStatement, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.Emit.EncLambdaInfo>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.LambdaRuntimeRudeEditInfo>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.Emit.EncClosureInfo>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.StateMachineStateDebugInfo>, Microsoft.CodeAnalysis.CSharp.StateMachineTypeSymbol, Microsoft.CodeAnalysis.CodeGen.VariableSlotAllocator, Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag, Microsoft.CodeAnalysis.CodeGen.DebugDocumentProvider, Microsoft.CodeAnalysis.CSharp.ImportChain, Boolean, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.SourceSpan>, AsyncForwardEntryPoint)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(Microsoft.CodeAnalysis.CSharp.TypeCompilationState)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at System.Threading.ThreadPoolWorkQueue.Dispatch()
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error : System.InvalidOperationException: Unexpected value 'NoConversion' of type 'Microsoft.CodeAnalysis.CSharp.ConversionKind'
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitConversion(BoundConversion conversion)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitConversionExpression(BoundConversion conversion, Boolean used)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitExpressionCoreWithStackGuard(BoundExpression expression, Boolean used)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitExpression(BoundExpression expression, Boolean used)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitReturnStatement(BoundReturnStatement boundReturnStatement)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatements(ImmutableArray`1 statements)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitUninstrumentedBlock(BoundBlock block)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.EmitStatement(BoundStatement statement)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl()
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(PEModuleBuilder moduleBuilder, MethodSymbol method, Int32 methodOrdinal, BoundStatement block, ImmutableArray`1 lambdaDebugInfo, ImmutableArray`1 orderedLambdaRuntimeRudeEdits, ImmutableArray`1 closureDebugInfo, ImmutableArray`1 stateMachineStateDebugInfos, StateMachineTypeSymbol stateMachineTypeOpt, VariableSlotAllocator variableSlotAllocatorOpt, BindingDiagnosticBag diagnostics, DebugDocumentProvider debugDocumentProvider, ImportChain importChainOpt, Boolean emittingPdb, ImmutableArray`1 codeCoverageSpans, AsyncForwardEntryPoint entryPointOpt)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(TypeCompilationState compilationState)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType)
    C:\Program Files\dotnet\sdk\9.0.100\Roslyn\Microsoft.CSharp.Core.targets(89,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 21, 2024
@jjonescz
Copy link
Member

Looks like a duplicate of #75569.

@aannenko
Copy link
Author

Yes, thanks. Should I close this one then?

@jjonescz jjonescz closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants