Skip to content

Map.+= not a member of Map[String, String] (using scala2-library-tasty) #19616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nicolasstucki opened this issue Feb 5, 2024 · 4 comments
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc area:scala2-library-tasty Any issue generaing or using the Scala 2 library TASTy itype:bug

Comments

@nicolasstucki
Copy link
Contributor

Compiler version

3.4.0-RC2

Minimized code

// Test.scala

def test: Unit =
  val sb = new StringBuilder
  var key = ""
  var map = Map.empty[String, String]
  map += key -> sb.toString()
sbt> set ThisBuild/Build.scala2Library := Build.Scala2LibraryCCTasty
sbt> scala3-bootstrapped/scalac Test.scala

Output

-- [E008] Not Found Error: Test.scala:5:6 ------------------------------------
5 |  map += key -> sb.toString()
  |  ^^^^^^
  |value += is not a member of Map[String, String] - did you mean Map[String, String].!=? or perhaps Map[String, String].++ or Map[String, String].++ or Map[String, String].==?

Expectation

Should compile as it does when we use the Scala 2 compiled library.

@nicolasstucki nicolasstucki added itype:bug area:scala2-library-tasty Any issue generaing or using the Scala 2 library TASTy labels Feb 5, 2024
@nicolasstucki
Copy link
Contributor Author

With the Scala 2 compiled library we get the transformation to map = map.+

map = map.+[String](ArrowAssoc[String](key).->[String](sb.toString()))

while with the TASTy library we fail to type map.+=

map.+=(ArrowAssoc[String](key).->[String](sb.toString))

@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented Feb 6, 2024

The issue is that StringBuilder defines a toString without parenthesis and we use it with parenthesis.

The original code can be fixed with

-  map += key -> sb.toString()
+  map += key -> sb.toString

We need a better error message and we might need to revise which definitions in the library should have or not parenthesis.

@nicolasstucki
Copy link
Contributor Author

Minimization

trait Map {
  def +(x: Any): Map
}
trait StringBuilder {
  def toString: String
}
def test(sb: StringBuilder): Unit =
  var map: Map = ???
  map += sb.toString()

@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented Feb 6, 2024

Using

trait StringBuilder {
  def toString(): String
}

seems to make both map += sb.toString and map += sb.toString() work.

@nicolasstucki nicolasstucki added the area:reporting Error reporting including formatting, implicit suggestions, etc label Feb 29, 2024
@hamzaremmal hamzaremmal self-assigned this Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc area:scala2-library-tasty Any issue generaing or using the Scala 2 library TASTy itype:bug
Projects
None yet
Development

No branches or pull requests

2 participants