❔ null warning while indexing (rather than accessing) null-agnostic type?
first, lets look at a scenario where everything behaves as expected:
but if we move
GetList
to another project that doesn't use nullables:
now we get the following behaviour:
can someone explain?29 Replies
ElementAt
is an extension method on IEnumerable<T>
i know, what about it?
that's why it doesn't generate a warning
however its not while accessing the variableyou aren't accessing
myList
in that call
you're passing myList
to Enumerable.ElementAt
then why does it give a warning in the first example ?
some
var
shenanigans
i assumethats not very helpful
Hold on what is your actual question? Why disabling nullable... disables nullable?
oh nvm, now I see it
That is extremely odd
coworker and i lost our minds over this yesterday, im on the edge of reporting this as a bug
You could try asking in #roslyn
will do
can't repro
Wasn't it in another project?
correct
no clue how you gathered that from the information provided lol
but if we move GetList to another project that doesn't use nullables:in the op
same diff
what?
ah wait
forgot the
using System.Linq
LastExceed#8727
ok turns out i made 2 mistakes at the same time:
1) i forgot that not only the array itself, but also the items inside the array can be null
2) i tried
and wondered why there's a null warning on the first line but not the second. i forgot that a variable only needs to be null checked once, so the warning will only show once as well. if you comment out the first line the warning will show on the second instead
thats embarrasing
Quoted by
<@!173538718886395906> from #roslyn (click here)
React with ❌ to remove this embed.
$close
Use the
/close
command to mark a forum thread as answeredAlso, to be clear, there is no "configuring interpretation of null agnostic types to be pessimistic"
That's not a thing that exists
I was confused about that too
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.