Scala Programming Language
  1. Scala Programming Language
  2. SI-6138

alternatives error message should not be empty

    Details

      Description

      
      scala> def getClassSafe(fullName: String): Option[String] = try {
           |                Some(definitions.getClass(newTypeName(fullName)))
           |              } catch {
           |                case _: MissingRequirementError => None
           |              }
      <console>:39: error: too many arguments for overloaded method value getClass with alternatives:
      
      
                            Some(definitions.getClass(newTypeName(fullName)))
                                                     ^
      

      note the cliff hanger, there – no alternatives are reported

      I think the problem is that the getClass symbol is overloaded, but the tree's type is already <error> by the time the error message is synthesized (the error arises from the erroroneous return type `Option[String]`)

      Taking the relevant pieces of code:

      if (sym.isOverloaded) overloadedMessage
      
      def overloadedMessage = "overloaded method " + sym + " with alternatives:\n" + alternativesString(tree)
      
      def alternativesString(tree: Tree) =
        alternatives(tree) map (x => "  " + methodTypeErrorString(x)) mkString ("", " <and>\n", "\n")
      
      def alternatives(tree: Tree): List[Type] = tree.tpe match {
        case OverloadedType(pre, alternatives)  => alternatives map pre.memberType
      
      

      this assumes `tree.symbol.isOverloaded` implies `tree.tpe.isInstanceOf[OverloadedType]`, which this bug illustrates is not necessarily the case

        Activity

        Hide
        Hubert Plociniczak added a comment -

        Surprisingly, this is not a regression. I wonder how it survived for so long.

        Show
        Hubert Plociniczak added a comment - Surprisingly, this is not a regression. I wonder how it survived for so long.
        Hide
        James Iry added a comment -

        2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.

        Show
        James Iry added a comment - 2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.
        Hide
        James Iry added a comment -

        2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.

        Show
        James Iry added a comment - 2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/2578

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Adriaan Moors
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development