dotnet/roslyn

Property patterns and dynamic

Offen

#28.933 geöffnet am 29.07.2018

 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (4.257 Forks)batch import
Area-CompilersBugConcept-Diagnostic ClarityFeature - Pattern Matchinghelp wanted

Repository-Metriken

Stars
 (20.414 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)

Beschreibung

Version Used: SharpLab for branch features/recursive-patterns from 24 Jul 2018 (commit b364cfc)

Steps to Reproduce:

Try to compile the following code:

class C
{
    void M(dynamic o)
    {
        _ = o is { Foo: 42 };
    }
}

Expected Behavior:

Since code like o is { Foo: 42 } normally compiles to the equivalent of o != null && o.Foo == 42 and since that code is valid for o of type dynamic, I would expect the above method to compile.

Actual Behavior:

error CS0117: 'dynamic' does not contain a definition for 'Foo'

I think the error message is somewhat confusing, because the whole point of dynamic is that it's not checked at compile time whether a member exists.


As usual with work-in-progress features, it's not clear to me if this is by design, not implemented yet, just a confusing error message or an actual bug, so feel free to handle this issue accordingly.

Contributor Guide