Pre-SIP: cosmetic enhancements

Try changing the oder, java.lang first then scala then scala.Predef


Hey, thanks, that worked! But that’s just the start. It replicates the default imports, but I am still having a problem with adding my own custom “Predef”. I tried this little test:

scalacOptions += “-Yimports:java.lang,scala,scala.Predef,myPackage.test1”

where “myPackage.test1” exists. And here is the result:

[error] error: bad preamble import myPackage.test1

What am I missing?

If you’re adding your own (the one that you defined) objects/packages etc they need to live in a separate build unit. This could either be another sub-project in sbt or if you’re building a library and always want to import it, you could also publish it as a jar and depend on it in the binary way (as opposed to source code). No matter what you do you can’t autoimport things in the same build.

1 Like

Thanks. Would it be possible for the error message to provide a clue? Or perhaps a reference to a detailed documentation page on -Yimports?

1 Like

Don’t know. I’m not part of the compiler and/or Scala team. Just some guy on the internet…

1 Like

Yes, but a very useful guy on the Internet…

I’m glad to have discovered this feature. There are a couple of functions from my teaching library that I use all the time, and which reuse standard names from Predef. If I forget a manual import, I end up using the default functions instead, a mistake I may not catch at compile-time. Using -Yimports is now making my life easier.

1 Like