Skip to content
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

Failure in function literal adaptation to partial function #20197

Open
som-snytt opened this issue Apr 15, 2024 · 1 comment
Open

Failure in function literal adaptation to partial function #20197

som-snytt opened this issue Apr 15, 2024 · 1 comment
Labels
area:pattern-matching area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug

Comments

@som-snytt
Copy link
Contributor

Compiler version

3.4.1

Minimized code

Welcome to Scala 3.4.1 (21.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> List(42).collect((x: Any) => x match { case "42" => 27 })
1 warning found
-- [E030] Match case Unreachable Warning: ------------------------------------------------------------------------------
1 |List(42).collect((x: Any) => x match { case "42" => 27 })
  |                                            ^^^^
  |                                            Unreachable case
java.lang.AbstractMethodError: Receiver class rs$line$1$$anon$1 does not define or inherit an implementation of the resolved method 'abstract boolean isDefinedAt(java.lang.Object)' of interface scala.PartialFunction.
  at scala.PartialFunction.applyOrElse(PartialFunction.scala:214)
  at scala.PartialFunction.applyOrElse$(PartialFunction.scala:213)
  at scala.runtime.AbstractPartialFunction.applyOrElse(AbstractPartialFunction.scala:27)
  at scala.collection.immutable.List.collect(List.scala:267)
  ... 33 elided

Output

It has progressed to warning.

Expectation

Not an abstract method error.

Noticed at related effort to align with dotty at scala/scala#10486

@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 15, 2024
@Gedochao Gedochao added area:reporting Error reporting including formatting, implicit suggestions, etc area:pattern-matching and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 16, 2024
@Gedochao
Copy link
Contributor

//> using scala 2.13.13
List(42).collect((x: Any) => x match { case "42" => 27 })

BTW for 2.13.13 it fails at compile time.

scala-cli repro-script.sc   
# Compiling project (Scala 2.13.13, JVM (17))
# [error] ./repro-script.sc:2:45
# [error] type mismatch;
# [error]  found   : String("42")
# [error]  required: Int
# [error] List(42).collect((x: Any) => x match { case "42" => 27 })
# [error]                                             ^
# Error compiling project (Scala 2.13.13, JVM (17))

While on Scala 3 (both LTS & Next) we just get a warning and then a failure at runtime.

scala-cli repro-script.sc -S 3.4.1
# [warn] ./repro-script.sc:2:45
# [warn] Unreachable case
# [warn] List(42).collect((x: Any) => x match { case "42" => 27 })
# [warn]                                             ^^^^
# Exception in thread "main" java.lang.AbstractMethodError: Receiver class repro$minusscript$_$$anon$1 does not define or inherit an implementation of the resolved method 'abstract boolean isDefinedAt(java.lang.Object)' of interface scala.PartialFunction.
#         at scala.PartialFunction.applyOrElse(PartialFunction.scala:214)
#         at scala.PartialFunction.applyOrElse$(PartialFunction.scala:213)
#         at scala.runtime.AbstractPartialFunction.applyOrElse(AbstractPartialFunction.scala:27)
#         at scala.collection.immutable.List.collect(List.scala:267)
#         at repro$minusscript$_.<init>(repro-script.sc:2)
#         at repro$minusscript_sc$.script$lzyINIT1(repro-script.sc:16)
#         at repro$minusscript_sc$.script(repro-script.sc:16)
#         at repro$minusscript_sc$.main(repro-script.sc:20)
#         at repro$minusscript_sc.main(repro-script.sc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:pattern-matching area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
Development

No branches or pull requests

2 participants