Skip to content

Compiler Prediction Error #3485

@KoromaruKoruko

Description

@KoromaruKoruko

General

Version : 3.1
VisualStudio: 2019 16.5.4

public Boolean TryTest(String X, out String Y)
{
    Lazy<Dictionary<String, String>> A, B;
    if (A.IsValueCreated ? A.Value.TryGetValue(X, out Y) : false
        || B.IsValueCreated ? B.Value.TryGetValue(X, out Y) : false)
        return true
    Y = null;
    return false
}

is the same as

public Boolean TryTest(String X, out String Y)
{
    Lazy<Dictionary<String, String>> A, B;
    if (A.IsValueCreated && A.Value.TryGetValue(X, out Y)
        || B.IsValueCreated && B.Value.TryGetValue(X, out Y))
        return true
    Y = null;
    return false
}

the above snippet works with no issue but the first one will throw a compile error stating that Y would not be set by the if-statements return.

this has no real implications with this example as using && is by far much better then using ? : but as it stands it is an error in the compilers ability to predict and as such should be fixed as it may have some other unforeseen implication in another project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions