Skip to content

trivial quoted pattern is refutable #16649

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

Closed
bishabosha opened this issue Jan 10, 2023 · 2 comments · Fixed by #16674
Closed

trivial quoted pattern is refutable #16649

bishabosha opened this issue Jan 10, 2023 · 2 comments · Fixed by #16674
Assignees
Labels
Milestone

Comments

@bishabosha
Copy link
Member

bishabosha commented Jan 10, 2023

Compiler version

3.2.1

Minimized code

import quoted.*

def foo(using Quotes)(x: Expr[Any]): Expr[Unit] =
  val '{ $y: Any } = x
  val '[List[Int]] = Type.of[List[Int]]
  '{}

Output

-- Warning: --------------------------------------------------------------------
4 |  val '{ $y: Any } = x
  |      ^^^^^^^^^^^^^^^^
  |pattern binding uses refutable extractor `x$1.asInstanceOf[scala.quoted.runtime.QuoteMatching].ExprMatch`
  |
  |If this usage is intentional, this can be communicated by adding `: @unchecked` after the expression,
  |which may result in a MatchError at runtime.
-- Warning: --------------------------------------------------------------------
5 |  val '[List[Int]] = Type.of[List[Int]]
  |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |pattern binding uses refutable extractor `x$1.asInstanceOf[scala.quoted.runtime.QuoteMatching].TypeMatch`
  |
  |If this usage is intentional, this can be communicated by adding `: @unchecked` after the expression,
  |which may result in a MatchError at runtime.

Expectation

It seems these patterns should always bind? can the refutability be improved or is it not possible

originally from the tests as seen here:
https://github.com/lampepfl/dotty/blob/4fa0715f20e7cabfae04defc4c3a71aa994578b4/tests/run-macros/paramSymss/Macro_1.scala#L8

@bishabosha bishabosha added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 10, 2023
@bishabosha bishabosha added area:metaprogramming:quotes Issues related to quotes and splices area:pattern-matching and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 10, 2023
@bishabosha
Copy link
Member Author

also perhaps printing of quoted pattern extractors could be improved

@nicolasstucki
Copy link
Contributor

We should be able to make quoted patterns irrefutable for

  • '{ $x: T } for a U <: T an a scrutinee of type Expr[U]
  • '{ $x: t }

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 12, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 12, 2023
@Kordyjan Kordyjan added this to the Future versions milestone Jan 13, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 16, 2023
@Kordyjan Kordyjan modified the milestones: Future versions, 3.3.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants