- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
"could not inline" warning
Sat, 2010-06-05, 22:51
Hi,
so I have this seemingly innocent code with an explicit shelf type ;-)
case class Book(id: Int, name: String)
case class Shelf(books: Map[Int, Book]) {
def add(b: Book) = copy(books = books + (b.id -> b))
}
When compiled with "scalac -optimise shelf.scala", there's a warning being printed:
shelf.scala:4: warning: Could not inline required method -> because it is unsafe (target may reference private fields).
def add(b: Book) = books + (b.id -> b)
^
Now, since warnings usually want to tell me that I am doing something can anybody enlighten me what I am doing wrong and what I could do better at that position?
Of course "copy(books = books updated (b.id, b))" gets rid of the warning... but I find that much less expressive.
Any suggestions? (I'm on RC3, btw)
Thanks
Andreas
Sat, 2010-06-05, 23:27
#2
Re: "could not inline" warning
Thanks Paul.
Though I didn't suspect this to be a bug.
At least now I know and can leave the code untouched. :)
Andreas
On Sat, Jun 05, 2010 at 11:51:03PM +0200, Andreas Flierl wrote:
> shelf.scala:4: warning: Could not inline required method -> because it is unsafe (target may reference private fields).
> def add(b: Book) = books + (b.id -> b)
> ^
>
> Now, since warnings usually want to tell me that I am doing something
> can anybody enlighten me what I am doing wrong and what I could do
> better at that position?
What you are doing wrong: ignoring the bug database.
What you could do better: embrace the bug database.
https://lampsvn.epfl.ch/trac/scala/ticket/3420
"Could not inline required method -> because it is unsafe"