Skip to content

Fix #2378: Better error message for extractors #2386

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

Merged
merged 2 commits into from
May 6, 2017

Conversation

odersky
Copy link
Contributor

@odersky odersky commented May 6, 2017

No description provided.

@odersky odersky requested a review from liufengyun May 6, 2017 11:15
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it produces the following error message, which is incorrect:

-- Error: examples/abstract.scala:11:9 -----------------------------------------
11 |    case Apply(fun, args) => 3
   |         ^^^^^
   |Apply cannot be used as an extractor in a pattern because it lacks an unapply or unapplySeq method

one error found

BTW, it seems you accidentally added scala-scala.

For the overloaded extractors, following test case is preferred:

trait Cap
trait Tree

object Apply {
  def unapply(tree: Tree): Option[(Tree, Seq[Tree])] = ???
  def unapply(tree: Tree)(implicit c: Cap): Option[(Tree, Seq[Tree])] = ???
}

class Test {
  def foo(tree: Tree): Int = tree match {
    case Apply(fun, args) => 3
  }
}

@odersky
Copy link
Contributor Author

odersky commented May 6, 2017

Now it produces the following error message, which is incorrect:

I know... But it's better then what we had, no? It's surprisingly difficult to do better. I tried, but had to postpone due to lack of time.

BTW, it seems you accidentally added scala-scala.

Ah, that seems to be the source of my problems. Git claims it's a modified file that needs to be added. But if I do that CI breaks. It would be good if someone told me what the issue here is.

@liufengyun
Copy link
Contributor

Git claims it's a modified file that needs to be added. But if I do that CI breaks. It would be good if someone told me what the issue here is.

The simple rule works for me is: if there's no reason to forward a submodule to a specific new version, never add changes in the submodule folder. The changes might be some generated files that are not added to .gitignore of the submodule.

It's surprisingly difficult to do better. I tried, but had to postpone due to lack of time.

I see it's difficult to do given our current tryEither, typeIdent, typeSelect structure. Later we can consider refactor parts of typeIdent and typeSelect to a standalone NameResolution, which may help. I agree we can address this later.

BTW, you need to using the following test case, as the original test case is already fixed in #2358 .

trait Cap
trait Tree

object Apply {
  def unapply(tree: Tree): Option[(Tree, Seq[Tree])] = ???
  def unapply(tree: Tree)(implicit c: Cap): Option[(Tree, Seq[Tree])] = ???
}

class Test {
  def foo(tree: Tree): Int = tree match {
    case Apply(fun, args) => 3
  }
}

@liufengyun liufengyun merged commit 5db8e84 into scala:master May 6, 2017
@liufengyun liufengyun deleted the fix-#2378 branch May 6, 2017 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants