scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Curried method: ambiguous reference to overloaded definition #12973

Closed He-Pin closed 6 months ago

He-Pin commented 6 months ago

Reproduction steps

Scala version: (Is the bug only in Scala 3.x? If so, report it at https://github.com/lampepfl/dotty/issues/new/choose instead.) Scala 2.13.13

  def iterate[T](seed: T)(f: T => T): Source[T, NotUsed] = iterate(seed)(ConstantFun.anyToTrue, f)

  def iterate[T](seed:T)(hasNext: T => Boolean, next: T => T): Source[T, NotUsed] =
    fromIterator(() => new IterateIterator[T](seed, hasNext, next))
      .withAttributes(DefaultAttributes.iterableSource)

Problem

Curried methods overloading issue:

 ambiguous reference to overloaded definition,
[error] both method iterate in object Source of type [T](seed: T)(hasNext: T => Boolean, next: T => T): org.apache.pekko.stream.scaladsl.Source[T,org.apache.pekko.NotUsed]
[error] and  method iterate in object Source of type [T](seed: T)(f: T => T): org.apache.pekko.stream.scaladsl.Source[T,org.apache.pekko.NotUsed]
[error] match argument types (T)
[error]   def iterate[T](seed: T)(f: T => T): Source[T, NotUsed] = iterate(seed)(ConstantFun.anyToTrue, f)
[error]                                                            ^
[error] one error found
[error] (stream / Compile / compileIncremental) Compilation failed

This code compiles in Scala 3.3.3, hope it works in Scala 2.12/2.13 too

som-snytt commented 6 months ago

The issue template should say

Hopes are not bug reports

https://docs.scala-lang.org/scala3/reference/changed-features/overload-resolution.html#looking-beyond-the-first-argument-list-1

This is how it works in Scala 2; there likely is not a change of sufficiently small scope to support cross-compilation. The feature was to support extension methods, which share a common first parameter list.

SethTisue commented 6 months ago

Yeah, would be nice if this were in scope for Scala 2, but it isn't.