seanjensengrey / kiama

Automatically exported from code.google.com/p/kiama
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Improve error message when dup fails #66

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The dup method in rewriting fails if the class whose instance it is trying to 
create is nested inside another class (since an owner for the inner instance 
will not be provided to the constructor). We should try to improve the message 
that is produced in this case since dup rarely fails for other reasons.

Simeon Fitch suggests:

Since it’s a JVM or scalac issue (not one with Kiama), a “fix” isn’t 
warranted, but the error message might be improved to point in that direction. 
Is Class.isMemberClass something that could be used to refine the message for 
this case?

http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#isMemberClass()

At least in my case it correctly detects the case class being defined inside a 
worksheet and ScalaTest context. Something to consider.

Original issue reported on code.google.com by inkytonik on 29 Jun 2014 at 12:18

GoogleCodeExporter commented 9 years ago
It appears that isMemberClass will not do what we need since it seems to return 
true also in the case where a term/tree class is a member of an (singleton) 
object (as opposed to a class). In the object case dup does not fail since no 
outer owner reference is needed).

For the time-being I have added a hint to the message that is produced when dup 
fails in this circumstance, pointing out that nesting classes inside another 
class is a common cause of this failure (r810ae0de1cfb)

Original comment by inkytonik on 24 Jul 2014 at 11:59