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

Compiler Prediction Error #3485

Closed
KoromaruKoruko opened this issue May 16, 2020 · 4 comments
Closed

Compiler Prediction Error #3485

KoromaruKoruko opened this issue May 16, 2020 · 4 comments

Comments

@KoromaruKoruko
Copy link

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.

@scalablecory scalablecory transferred this issue from dotnet/core May 21, 2020
@RikkiGibson
Copy link
Contributor

This feature request requires that we amend the definite assignment specification. Therefore moving to csharplang.

@RikkiGibson RikkiGibson transferred this issue from dotnet/roslyn May 21, 2020
@333fred
Copy link
Member

333fred commented May 21, 2020

This is very similar to #3365.

@ntovas
Copy link

ntovas commented May 22, 2020

Maybe the compiler don't analyze the A.Value.TryGetValue(X, out Y) in respect to the if statements context? And most importantly, should it?

@KoromaruKoruko
Copy link
Author

it is the exact same as reported in #3365 so ignore this thread, and move to that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants