Note [Desugaring overloaded list patterns]
If OverloadedLists is enabled, we desugar a list pattern to a view pattern: [p1, p2, p3] ==> toList -> [p1, p2, p3] This happens directly in the renamer, using the HsPatExpansion mechanism detailed in Note [Rebindable syntax and XXExprGhcRn]. Note that we emit a special view pattern: we additionally keep track of an inverse to the pattern. See Note [Invertible view patterns] in GHC.Tc.TyCl.PatSyn for details. == Wrinkle == This is all fine, except in one very specific case: When the type being matched on is already a list type, so that the pattern looks like toList @[ty] dict -> pat then we know for certain that `toList` is an identity function, so we can behave exactly as if the pattern was just `pat`. This is important when we have `OverloadedLists`. For example (#14547, #25257) > {-# LANGUAGE OverloadedLists #
References 2
- Rebindable syntax and XXExprGhcRn GHC.Hs.Expr
- Invertible view patterns GHC.Tc.TyCl.PatSyn
Referenced by 5
- GHC.Hs.Pat call site
- GHC.HsToCore.Pmc.Desugar call site
- Handling overloaded and rebindable patterns GHC.Rename.Pat
- GHC.Rename.Pat call site
- GHC.Tc.Gen.Pat call site