Skip to content

Local imports occasionally don't work #15468

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

Closed
japgolly opened this issue Jun 17, 2022 · 3 comments · Fixed by #15477
Closed

Local imports occasionally don't work #15468

japgolly opened this issue Jun 17, 2022 · 3 comments · Fixed by #15477
Milestone

Comments

@japgolly
Copy link
Contributor

Compiler version

3.1.2

Minimized code

object Test {
  val s = ""
  import s.{length => x, size => y}
  locally(x) // ok
  locally(y) // Not found: y
}

Output

[error] 5 |  locally(y) // Not found: y
[error]   |          ^
[error]   |          Not found: y
[error] one error found

Expectation

It should compile.

@japgolly japgolly added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 17, 2022
@som-snytt
Copy link
Contributor

You don't get implicit augmentation in import clauses.

object Test {
  val s = ""
  val x = augmentString(s)
  import x.{size => z}
  locally(z) // Not found: y
  import s.{length => x, size => y}
  locally(x) // ok
  //locally(y) // Not found: y
  locally(s.size) // Not found: y
}

shows

[[syntax trees at end of                     typer]] // i15468.scala
package <empty> {
  final lazy module val Test: Test = new Test()
  final module class Test() extends Object() { this: Test.type =>
    val s: String = ""
    val x: scala.collection.StringOps = augmentString(Test.s)
    import Test.x.{size as z}
    locally[Int](Test.x.size)
    import Test.s.{length as x, size as y}
    locally[scala.collection.StringOps](Test.x)
    locally[Int](augmentString(Test.s).size)
  }
}

[[syntax trees at end of          inlinedPositions]] // i15468.scala: unchanged since typer
-- [E008] Not Found Error: i15468.scala:7:25 ---------------------------------------------------------------------------
7 |  import s.{length => x, size => y}
  |                         ^^^^
  |                         value size is not a member of String - did you mean s.lines?

@som-snytt
Copy link
Contributor

Possibly Scala 2 wins this round.

i15468.scala:7: error: value size is not a member of String
  import s.{length => x, size => y}
         ^
i15468.scala:7: warning: imported `x` is permanently hidden by definition of value x in object Test
  import s.{length => x, size => y}
            ^

@som-snytt
Copy link
Contributor

som-snytt commented Jun 17, 2022

You don't get implicit augmentation in import clauses.

But maybe you should! So many values get stabilized, why not import qualifier? Import clauses are selections, too. That slogan went stale.

odersky added a commit to dotty-staging/dotty that referenced this issue Jun 19, 2022
Import selectors were checked  at PostTyper before, but that can lead
to confusion when a type error results from a bad import selector.

Fixes scala#15468
@odersky odersky removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Jun 19, 2022
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants