hylo icon indicating copy to clipboard operation
hylo copied to clipboard

Silence name lookup diagnostics stemming from declarations having been assigned an error type

Open dabrahams opened this issue 2 years ago • 5 comments

At 30dacf0f8

//- 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()
}

dabrahams avatar Jan 04 '24 18:01 dabrahams

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.

kyouko-taiga avatar Jan 18 '24 15:01 kyouko-taiga

Might it be better if name lookup did not ignore declarations with errors?

dabrahams avatar Jan 19 '24 02:01 dabrahams

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.

kyouko-taiga avatar Jan 19 '24 10:01 kyouko-taiga

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).

dabrahams avatar Jan 19 '24 22:01 dabrahams

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.

kyouko-taiga avatar Jan 19 '24 22:01 kyouko-taiga