compiler construction - Strange behaviour when importing types in Scala 2.10 -
today cleared .ivy cache , cleaned project output targets. since have been getting unusual behaviour when running tests sbt or editing in scala ide.
given following:
package com.abc.rest import com.abc.utility.idtlabel
i next error:
object utility not fellow member of bundle com.abc.rest.com.abc
notice com.abc
repeated twice, appears compiler uses context of current bundle when doing import (maybe it's supposed this, never noticed before).
also, if seek access classes in bundle com.abc
anywhere within com.abc.rest
(even using total path) compiler complain type can not found.
it appears errors occur when seek include files parent packages. find unusual code used work. started happening after cleaned project , ivy cache, maybe later version of compiler more strict previous one.
i love ideas on can doing wrong, or how can go troubleshooting this.
update:
by first importing parent classes , defining current package, problem goes away:
import com.abc.utility.idtlabel import com.abs._ bundle com.abc.rest { // define classes belonging com.abc.rest here }
so works, still love know why on earth other way around worked, , stopped working, , how on earth can prepare it. had look, , find no packages, objects or traits name of com anywhere within parent package.
update relating worksheets:
scala worksheets belonging same bundle share same scope, sounds obvious, wasn't. worksheets not sand-boxed - can see project, and project can see them. 'test' object, traits, , classes create within worksheet files, becomes visible in rest of project.
i have many worksheets did not seek see problem came in. moved them own package, , magic, problem went away.
so, lesson learned day: if create stuff within worksheets, it's visible outside worksheet.
anyway, new found knowledge come in handy, meaning 'interesting' can build, monitored , tweaked within worksheet, while rest of project can utilize it. quite cool actually.
it's still interesting think how sbt clean
, cleaned ivy cache managed highlight problem hidden before, hey, that's story....
(at request of jacobusr, i'm making proper reply out of before comments).
this can happen if have defined class/trait/object within bundle com.abc.rest.com
. bundle com.abc.rest.com
exists, , given in bundle com.abc.rest
, com
designate com.abc.rest.com
opposed _root_.com
. fastest (but non-conclusive) way check, without scanning source files, .class files in "com/abc/rest/com" sub-folder.
in particular behaviour if of files has duplicate bundle definitions (as in bundle com.abc.rest; bundle com.abc.rest; ...
). if have duplicate bundle clause somewhere in same file error, wouldn't see fishy .class files, failure @ compiling file prevent generation of .class files class definition within file.
the final bit of useful info found out scala worksheets not sandboxed, , define in worksheets affects project's code (rather having project's code affecting worksheet). duplicate bundle clause in worksheet cause error got.
scala compiler-construction sbt scala-2.10
No comments:
Post a Comment