Skip to content

Commit

Permalink
Mention if missing class is on the class path
Browse files Browse the repository at this point in the history
Hint if there is an object in scope, in a package,
which has a class, and the class path finds it.
  • Loading branch information
som-snytt committed May 7, 2024
1 parent 3fb0c39 commit a41bb8c
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/backend/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ trait Platform {
* Tells whether a class with both a binary and a source representation
* (found in classpath and in sourcepath) should be re-compiled. Behaves
* on the JVM similar to javac, i.e. if the source file is newer than the classfile,
* a re-compile is triggered. On .NET by contrast classfiles always take precedence.
* a re-compile is triggered.
*/
def needCompile(bin: AbstractFile, src: AbstractFile): Boolean
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett
val XmixinForceForwarders = ChoiceSetting(
name = "-Xmixin-force-forwarders",
helpArg = "mode",
descr = "Generate forwarder methods in classes inhering concrete methods from traits.",
descr = "Generate forwarder methods in classes inheriting concrete methods from traits.",
choices = List("true", "junit", "false"),
default = "true",
choicesHelp = List(
Expand Down
7 changes: 4 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,10 @@ trait ContextErrors extends splain.SplainErrors {
def AmbiguousIdentError(tree: Tree, name: Name, msg: String) =
NormalTypeError(tree, "reference to " + name + " is ambiguous;\n" + msg)

def SymbolNotFoundError(tree: Tree, name: Name, owner: Symbol, startingIdentCx: Context, inPattern: Boolean) = {
def help = if (inPattern && name.isTermName) s"\nIdentifiers ${if (name.charAt(0).isUpper) "that begin with uppercase" else "enclosed in backticks"} are not pattern variables but match the value in scope." else ""
NormalTypeError(tree, s"not found: ${decodeWithKind(name, owner)}$help")
def SymbolNotFoundError(tree: Tree, name: Name, owner: Symbol, inPattern: Boolean, hidden: Boolean) = {
val help = if (inPattern && name.isTermName) s"\nIdentifiers ${if (name.charAt(0).isUpper) "that begin with uppercase" else "enclosed in backticks"} are not pattern variables but match the value in scope." else ""
val path = if (hidden) s"\nA definition on the class path may be hidden by a source artifact. (Companions must be defined together.)" else ""
NormalTypeError(tree, s"not found: ${decodeWithKind(name, owner)}$help$path")
}

// typedAppliedTypeTree
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Namers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ trait Namers extends MethodSynthesis {
if (existingModule.isModule && !existingModule.hasPackageFlag && inCurrentScope(existingModule) && (currentRun.canRedefine(existingModule) || existingModule.isSynthetic)) {
updatePosFlags(existingModule, tree.pos, moduleFlags)
setPrivateWithin(tree, existingModule)
existingModule.moduleClass andAlso (setPrivateWithin(tree, _))
existingModule.moduleClass.andAlso(setPrivateWithin(tree, _))
context.unit.synthetics -= existingModule
tree.symbol = existingModule
}
Expand Down
14 changes: 13 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5669,7 +5669,19 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
case LookupInaccessible(symbol, msg) => issue(AccessError(tree, symbol, context, msg))
case LookupNotFound =>
asTypeName orElse inEmptyPackage orElse lookupInRoot(name) match {
case NoSymbol => issue(SymbolNotFoundError(tree, name, context.owner, startContext, mode.in(all = PATTERNmode, none = APPSELmode | TYPEPATmode)))
case NoSymbol =>
val hidden = !unit.isJava && name.isTypeName && {
startContext.lookupSymbol(name.toTermName, _ => true) match {
case LookupSucceeded(qualifier, symbol) if symbol.owner.hasPackageFlag =>
symbol.owner.info.decls.lookupAll(name).toList match {
case other :: Nil =>
other.sourceFile == null && classPath.classes(symbol.owner.fullNameString).find(_.name == name.toString).isDefined
case _ => false
}
case _ => false
}
}
issue(SymbolNotFoundError(tree, name, context.owner, inPattern = mode.in(all = PATTERNmode, none = APPSELmode | TYPEPATmode), hidden = hidden))
case oksymbol => typed1(tree.setSymbol(oksymbol), mode, pt)
}
case LookupSucceeded(qual, symbol) =>
Expand Down
7 changes: 3 additions & 4 deletions src/reflect/scala/reflect/internal/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package scala
package reflect
package internal

import scala.annotation.tailrec
import scala.collection.immutable
import scala.collection.mutable.ListBuffer
import util.{ ReusableInstance, Statistics, shortClassOfInstance }
import Flags._
import scala.annotation.tailrec
import scala.reflect.io.{AbstractFile, NoAbstractFile}
import util.{ReusableInstance, Statistics, shortClassOfInstance}
import Flags._
import Variance._

trait Symbols extends api.Symbols { self: SymbolTable =>
Expand Down Expand Up @@ -363,7 +363,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
final def newImport(pos: Position): TermSymbol =
newTermSymbol(nme.IMPORT, pos)


final def newModuleSymbol(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): ModuleSymbol =
newTermSymbol(name, pos, newFlags).asInstanceOf[ModuleSymbol]

Expand Down
5 changes: 5 additions & 0 deletions test/files/neg/t12289.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
c_2.scala:3: error: not found: type T
A definition on the class path may be hidden by a source artifact. (Companions must be defined together.)
class C extends T
^
1 error
4 changes: 4 additions & 0 deletions test/files/neg/t12289/c_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package p {
object T
class C extends T
}
3 changes: 3 additions & 0 deletions test/files/neg/t12289/t_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package p {
trait T
}

0 comments on commit a41bb8c

Please sign in to comment.