From 953de75815d6763cf873ad666247b3e28fae464a Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Thu, 18 Feb 2021 15:12:49 +0100 Subject: [PATCH 1/2] Fix #11438: fix typo in match type docs snippet --- docs/docs/reference/new-types/match-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/reference/new-types/match-types.md b/docs/docs/reference/new-types/match-types.md index bcb508675020..7be51e6a09bd 100644 --- a/docs/docs/reference/new-types/match-types.md +++ b/docs/docs/reference/new-types/match-types.md @@ -67,7 +67,7 @@ use of the match type as the return type): def leafElem[X](x: X): LeafElem[X] = x match case x: String => x.charAt(0) case x: Array[t] => leafElem(x(9)) - case x: Iterable[t] => leafElem(x.next()) + case x: Iterable[t] => leafElem(x.head) case x: AnyVal => x ``` From 1fb3271d77aaf2eebd7031af0d321fa964978c4d Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Thu, 18 Feb 2021 15:16:24 +0100 Subject: [PATCH 2/2] Add test case --- tests/pos/11463.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/pos/11463.scala diff --git a/tests/pos/11463.scala b/tests/pos/11463.scala new file mode 100644 index 000000000000..79ac01e24c1d --- /dev/null +++ b/tests/pos/11463.scala @@ -0,0 +1,11 @@ +type LeafElem[X] = X match + case String => Char + case Array[t] => LeafElem[t] + case Iterable[t] => LeafElem[t] + case AnyVal => X + +def leafElem[X](x: X): LeafElem[X] = x match + case x: String => x.charAt(0) + case x: Array[t] => leafElem(x(9)) + case x: Iterable[t] => leafElem(x.head) + case x: AnyVal => x