Silence name lookup diagnostics stemming from declarations having been assigned an error type
dabrahams opened this issue · comments
At 30dacf0
//- compileAndRun expecting: success
fun test_rotate() {
var a = Array<Int>()
&a.append(0)
&a.append(1)
&a.append(2)
&a.append(3)
&a.append(4)
&a.append(5)
&a.append(6)
&a.append(7)
&a.append(8)
&a.append(9)
var i = 0
while i <= 10 {
var b = a.copy()
&b.rotate(to_start_at: i)
var j = 0
while j < 10 {
precondition(b[j] == a[(i + j) % 10]) // <== b is undefined in this scope
}
j += 1
}
}
public fun main() {
test_rotate()
}
The problem is not about scope visibility. The first error is about Array<Int>
having no copy
member and every other error stems from there. b
gets an error type since the type checker doesn't know what to infer and then name lookup ignores declarations with errors.
We could silence these additional diagnostics to improve the UX.
Might it be better if name lookup did not ignore declarations with errors?
But then we would be simply kicking the problem further down the road, as we'd end up with many errors of the form "'_' has no member 'foo'", which isn't that much greater for UX in my opinion.
That's not what I'd expect. I'd expect that it does have a member foo
but that foo
's type is indeterminate (usually represented by some internal error type).
Well then let's pin that idea for when we'll have time to invest in better diagnostics, because that will not be an easy one to pull off.