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

Compiler behavior when importing from Predef is not specified #13031

Open
noresttherein opened this issue Sep 4, 2024 · 4 comments
Open

Compiler behavior when importing from Predef is not specified #13031

noresttherein opened this issue Sep 4, 2024 · 4 comments
Milestone

Comments

@noresttherein
Copy link

noresttherein commented Sep 4, 2024

Hi!
It's been a while.

Reproduction steps

Scala version: 2.13.14

import Predef.implicitly

object PredefBug {
	class P
	def test[X](x :X)(implicit p :X => P) :P = p(x)
	test { new P }

	???
}

Problem

implicit error;
!I p: PredefBug.P => PredefBug.P
  No implicit view available from PredefBug.P => PredefBug.P.
  
	test { new P }

/home/turin/porn/sugar/src/test/scala/PredefBug.scala:9
not found: value ???
	???
@som-snytt
Copy link

It's a long-standing behavior that explicitly importing from a "root context module" turns off the "default root import" from that module.

That behavior is honored under -Yimports where the module is arbitrary and not only scala.Predef.

I'm surprised to see that it's not in the spec, apparently. Root contexts are described in chapter 2, so "excluding import" should also be specified there. The exclusion applies to objects but not to packages.

@noresttherein
Copy link
Author

Oh, I'm sorry then. I kind of get an idea why, although in the era of IDEs being smart, but not enough, occasionally IntelliJ decides to import something moronic even though I wasn't even using implicitly. Not Scala's fault, of course, just that it wasn't me being dliberately stupid or malicious.

@som-snytt som-snytt changed the title Importing Predef.implicitly makes scalac blind. Compiler behavior when importing from Predef is not specified Sep 5, 2024
@som-snytt
Copy link

Another reason to update the spec is that scalac tries to "detect" the import, but in general the import may be nested; not sure if dotty requires the import to be top-level and at the top of the file.

@noresttherein
Copy link
Author

noresttherein commented Sep 9, 2024 via email

@lrytz lrytz assigned lrytz and unassigned lrytz Sep 11, 2024
@lrytz lrytz added this to the Backlog milestone Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants