Skip to content

Typing deviation in getOrElse #1045

Closed
Closed
@DarkDimius

Description

@DarkDimius
import scala.collection._
object T {
  val newSymbolMap: mutable.HashMap[String, mutable.HashMap[Int, Double]] = mutable.HashMap.empty
  val map = newSymbolMap.getOrElse("a", mutable.HashMap.empty)
  map.put(1, 0.0)
  newSymbolMap.put("a", map)
}

Compiles fine with scalac. Fails in dotty:

reproduce.scala:5: error: type mismatch:
 found   : Int(1)
 required: T.map.A
  map.put(1, 0.0)
          ^
reproduce.scala:5: error: type mismatch:
 found   : Double(0.0)
 required: T.map.B
  map.put(1, 0.0)
             ^
reproduce.scala:6: error: type mismatch:
 found   : (scala.collection.mutable.HashMap[Int, Double] |
  scala.collection.mutable.HashMap[Nothing, Nothing]
)(T.map)
 required: collection.mutable.HashMap[Int, Double]
  newSymbolMap.put("a", map)
                        ^
three warnings found
three errors found

This code is part of #630 and it used to compile fine.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions