This page is no longer maintained — Please continue to the home page at www.scala-lang.org

"could not inline" warning

2 replies
Aydjen
Joined: 2009-08-21,
User offline. Last seen 1 year 28 weeks ago.

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

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: "could not inline" warning

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"

Aydjen
Joined: 2009-08-21,
User offline. Last seen 1 year 28 weeks ago.
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

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland