@@ -16,6 +16,7 @@ import annotation.tailrec
16
16
import util .SimpleIdentityMap
17
17
import util .Stats
18
18
import java .util .WeakHashMap
19
+ import scala .util .control .NonFatal
19
20
import config .Config
20
21
import reporting .diagnostic .Message
21
22
import reporting .diagnostic .messages .BadSymbolicReference
@@ -2081,6 +2082,7 @@ object SymDenotations {
2081
2082
2082
2083
private var packageObjsCache : List [ClassDenotation ] = _
2083
2084
private var packageObjsRunId : RunId = NoRunId
2085
+ private var ambiguityWarningIssued : Boolean = false
2084
2086
2085
2087
/** The package objects in this class */
2086
2088
def packageObjs (implicit ctx : Context ): List [ClassDenotation ] = {
@@ -2163,13 +2165,24 @@ object SymDenotations {
2163
2165
// pick the variant(s) from the youngest class file
2164
2166
val lastModDate = assocFiles.map(_.lastModified).max
2165
2167
val youngest = assocFiles.filter(_.lastModified == lastModDate)
2168
+ val chosen = youngest.head
2169
+ def ambiguousFilesMsg (f : AbstractFile ) =
2170
+ em """ Toplevel definition $name is defined in
2171
+ | $chosen
2172
+ |and also in
2173
+ | $f"""
2166
2174
if youngest.size > 1 then
2167
- throw TypeError (em """ Toplevel definition $name is defined in
2168
- | ${youngest.head}
2169
- |and also in
2170
- | ${youngest.tail.head}
2171
- |One of these files should be removed from the classpath. """ )
2172
- multi.filterWithPredicate(_.symbol.associatedFile == youngest.head)
2175
+ throw TypeError (i """ ${ambiguousFilesMsg(youngest.tail.head)}
2176
+ |One of these files should be removed from the classpath. """ )
2177
+ def sameContainer (f : AbstractFile ): Boolean =
2178
+ try f.container == chosen.container
2179
+ catch case NonFatal (ex) => true
2180
+ if ! ambiguityWarningIssued then
2181
+ for conflicting <- assocFiles.find(! sameContainer(_)) do
2182
+ ctx.warning(i """ ${ambiguousFilesMsg(youngest.tail.head)}
2183
+ |Keeping only the definition in $chosen""" )
2184
+ ambiguityWarningIssued = true
2185
+ multi.filterWithPredicate(_.symbol.associatedFile == chosen)
2173
2186
end dropStale
2174
2187
2175
2188
if (symbol `eq` defn.ScalaPackageClass ) {
0 commit comments