Four await shapes decompile to uncompilable C#

Abierto
#4,015 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
csharp

Línea de trabajo

Comienza con los cuatro miembros que fallan en ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncAwaitPatternsBugs.cs, en la rama tests/async-await-patterns. Ejecuta los tests de async-await-patterns y luego inspecciona VisitAwait y el manejo de LdObjIfRef en ExpressionBuilder junto con los controles dynamic-call y record-with. La tarea estará terminada cuando los cuatro casos se decompilen a C# compilable y los tests del fixture pasen.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Four await shapes decompile to C# that does not compile. All four reproduce on
master @ 40e6f2cf2 and still reproduce after 257c96711 ("Avoid allowImplicitConversion: true
for await expressions"), which fixed a different set of await defects.

Each of them is covered by a member of ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncAwaitPatternsBugs.cs
on the tests/async-await-patterns branch, where the fixture is written as the C# that should
come out; the test is red for exactly these four.

1. Extension GetAwaiter taking its receiver by in
public struct ByRefReceiver
{
    public long A;
    public long B;
    public TaskAwaiter Self() => default(TaskAwaiter);
}

public static class ByRefExtensions
{
    public static TaskAwaiter GetAwaiter(this in ByRefReceiver receiver) => receiver.Self();
}

public async Task InReceiverExtensionAwaiter(ByRefReceiver value)
{
    await value;
}

decompiles to:

public unsafe async Task InReceiverExtensionAwaiter(ByRefReceiver value)
{
    await (ref *(ByRefReceiver*)value);
}

error CS1525: Invalid expression term 'ref'. The method also acquires an unsafe modifier it
did not have. The in parameter makes the awaited expression's expected type a
ByReferenceType; VisitAwait strips the DirectionExpression off the operand before
converting it.

2. await on a type parameter constrained to an awaitable interface
public interface IAwaitable
{
    TaskAwaiter GetAwaiter();
}

public async Task TypeParameterWithInterfaceConstraint<T>(T value) where T : IAwaitable
{
    await value;
}

decompiles to:

await (IAwaitable)/*OpCode not supported: LdObjIfRef*/;

error CS0119: 'IAwaitable' is a type, which is not valid in the given context. The operand is
not merely wrong, it is dropped: the constrained. callvirt lowers to an LdObjIfRef that
ExpressionBuilder has no case for.

3. dynamic await inside the argument list of a static call
public async Task DynamicAwaitInStaticCall(dynamic value)
{
    Console.WriteLine("x" + await value);
}

decompiles to:

Type typeFromHandle = typeof(Console);
typeFromHandle.WriteLine("x" + await value);

error CS1061: 'Type' does not contain a definition for 'WriteLine'. The call site's
typeof(TargetType) marker argument becomes the receiver. Isolated against two controls: the
same call without the await, and an instance dynamic call with an await, both decompile
correctly.

4. await inside a record with initializer
public record Record(int X);

public async Task<Record> WithExpressionContainingAwait(Record value)
{
    return value with { X = await Get() };
}

decompiles to:

Record record = value._003CClone_003E_0024();
Record record2 = record;
record2.X = await Get();
return record;

which does not compile. Isolated against two controls: value with { X = 1 } and
value with { X = Compute() } both round-trip as with expressions, so the await is what
defeats the transform.


Posted by an AI agent (Claude) on Siegfried's behalf.

Lenguaje dominante
C#
Estrellas
27.1k
Forks
3.8k
Merge medio
1 d 23 h
PR fusionados (30 d)
44

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de icsharpcode/ILSpy

Todos los issues de icsharpcode/ILSpy

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.