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

Nonsensical imports treated cause weird error messages #19413

Open
keynmol opened this issue Jan 10, 2024 · 4 comments
Open

Nonsensical imports treated cause weird error messages #19413

keynmol opened this issue Jan 10, 2024 · 4 comments
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug

Comments

@keynmol
Copy link
Contributor

keynmol commented Jan 10, 2024

Compiler version

3.3.1

Minimized code

import hello.bla.*

@main def hello = 
  test(1)

object kla:
  def ra = ???

import kla.bla.ra1
@main def test = 
  ra1()

Output

Compiling project (Scala 3.3.1, JVM (17))
[error] ./test.scala:10:12
[error] Cyclic reference involving val <import>
[error] import kla.bla.ra1
[error]            ^
Error compiling project (Scala 3.3.1, JVM (17))

Expectation

I would expect hello.bla import highlighted first, as it makes no sense - import from a function
But if you comment out everything after the hello function, you get only "test not found" error.

The "Cyclic reference" error is also confusing.

@keynmol keynmol added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 10, 2024
@som-snytt
Copy link
Contributor

Currently, the error is completely anonymous.

This is clean build at Scala compiler version 3.4.0-RC1-bin-SNAPSHOT-git-8039426 -- Copyright 2002-2024, LAMP/EPFL

[[syntax trees at end of                     typer]] // i19413.scala
package <empty> {
  import hello.bla.*
  final lazy module val kla: kla = new kla()
  final module class kla() extends Object() { this: kla.type =>
    def ra: <error unspecified error> = <error unspecified error>#bla.???
  }
  import kla.bla.ra1
  final lazy module val i19413$package: i19413$package = new i19413$package()
  final module class i19413$package() extends Object() { this: i19413$package.type =>
    @main def hello: <error unspecified error> = test()
    @main def test: <error unspecified error> = <error Cyclic reference involving val <import>>#ra1()
  }
}

[typer  in 586ms]
1 error found

Full disclosure

$ ~/projects/dotty/bin/scalac i19413.scala
1 error found

@nicolasstucki nicolasstucki added the area:reporting Error reporting including formatting, implicit suggestions, etc label Jan 11, 2024
@bishabosha bishabosha added better-errors Issues concerned with improving confusing/unhelpful diagnostic messages and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 11, 2024
@bishabosha
Copy link
Member

bishabosha commented Jan 11, 2024

in 3.4.0-RC1 repl I get this error:

-- [E008] Not Found Error: -----------------------------------------------------
10 |import kla.bla.ra1
   |       ^^^^^^^
   |       value bla is not a member of object kla
1 error found

if I remove the import and incorrect call to test now I have another error which also makes sense, but its different, it looks like it tried to apply an extension method?

scala> import hello.bla.*
     | 
     | @main def hello = 
     |   ???
     | 
     | object kla:
     |   def ra = ???
     | 
     | //import kla.bla.ra1
     | @main def test = 
     |   ???
     | 
-- [E007] Type Mismatch Error: -------------------------------------------------
1 |import hello.bla.*
  |       ^^^^^
  |Found:    (hello : => Nothing)
  |Required: ?{ bla: ? }
  |Note that implicit conversions were not tried because the result of an implicit conversion
  |must be more specific than ?{ bla: a type that can be selected or applied }
  |
  | longer explanation available when compiling with `-explain`
1 error found

@som-snytt
Copy link
Contributor

On the command line now,

➜  snips ~/projects/dotty/bin/scalac -version
Scala compiler version 3.4.2-RC1-bin-SNAPSHOT-git-4859415 -- Copyright 2002-2024, LAMP/EPFL
➜  snips ~/projects/dotty/bin/scalac -d /tmp/sandbox i19413.scala
1 error found
➜  snips ~/projects/dotty/bin/scalac -Vprint:typer -d /tmp/sandbox i19413.scala
[[syntax trees at end of                     typer]] // i19413.scala
package <empty> {
  import hello.bla.*
  final lazy module val kla: kla = new kla()
  final module class kla() extends Object() { this: kla.type =>
    def ra: <error unspecified error> = <error unspecified error>#bla.???
  }
  import kla.bla.ra1
  final lazy module val i19413$package: i19413$package = new i19413$package()
  final module class i19413$package() extends Object() { this: i19413$package.type =>
    @main def hello: <error unspecified error> = test()
    @main def test: <error unspecified error> =
      <error Cyclic reference involving val <import>

 Run with -explain-cyclic for more details.>#ra1()
  }
}

1 error found
➜  snips ~/projects/dotty/bin/scalac -explain-cyclic -Vprint:typer -d /tmp/sandbox i19413.scala
[[syntax trees at end of                     typer]] // i19413.scala
package <empty> {
  import hello.bla.*
  final lazy module val kla: kla = new kla()
  final module class kla() extends Object() { this: kla.type =>
    def ra: <error unspecified error> = <error unspecified error>#bla.???
  }
  import kla.bla.ra1
  final lazy module val i19413$package: i19413$package = new i19413$package()
  final module class i19413$package() extends Object() { this: i19413$package.type =>
    @main def hello: <error unspecified error> = test()
    @main def test: <error unspecified error> =

        <error Cyclic reference involving val <import>

The error occurred while trying to compute the signature of import hello.bla
  which required to compute the signature of method hello
  which required to compute the signature of method test
  which required to compute the signature of import kla.bla
  which required to compute the signature of import hello.bla

 Run with both -explain-cyclic and -Ydebug-cyclic to see full stack trace.>
        #ra1()
  }
}

1 error found

@som-snytt
Copy link
Contributor

if the def is not Nothing

[[syntax trees at end of                    parser]] // i19413b.scala
package <empty> {
  class C {
    import hello.bla.*
    def hello: String = ???
  }
}

-- [E008] Not Found Error: i19413b.scala:3:15 --------------------------------------------------------------------------
3 |  import hello.bla.*
  |         ^^^^^^^^^
  |         value bla is not a member of String
[[syntax trees at end of                     typer]] // i19413b.scala
package <empty> {
  class C() extends Object() {
    import this.hello.bla.*
    def hello: String = <error value bla is not a member of String>#???
  }
}

1 error found

as opposed to

[[syntax trees at end of                    parser]] // i19413b.scala
package <empty> {
  class C {
    import hello.bla.*
    def hello = ???
  }
}

-- [E007] Type Mismatch Error: i19413b.scala:3:9 -----------------------------------------------------------------------
3 |  import hello.bla.*
  |         ^^^^^
  |         Found:    (C.this.hello : => Nothing)
  |         Required: ?{ bla: ? }
  |         Note that implicit conversions were not tried because the result of an implicit conversion
  |         must be more specific than ?{ bla: a type that can be selected or applied }
  |
  | longer explanation available when compiling with `-explain`
[[syntax trees at end of                     typer]] // i19413b.scala
package <empty> {
  class C() extends Object() {
    import this.hello.*
    def hello: Nothing = ???
  }
}

1 error found

On the happy unhappy path, it notices the problem

[[syntax trees at end of                    parser]] // i19413b.scala
package <empty> {
  class C {
    import hello.length
    def hello: String = ???
  }
}

-- [E083] Type Error: i19413b.scala:4:9 --------------------------------------------------------------------------------
4 |  import hello.length
  |         ^^^^^
  |         (C.this.hello : => String) is not a valid import prefix, since it is not an immutable path
  |
  | longer explanation available when compiling with `-explain`
[[syntax trees at end of                     typer]] // i19413b.scala
package <empty> {
  class C() extends Object() {
    import this.hello.length
    def hello: String = ???
  }
}

1 error found

I don't even know what it means for a path to be immutable, as opposed to stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug
Projects
None yet
Development

No branches or pull requests

4 participants