Skip to content

Commit 29ecd88

Browse files
committed
Add optionless support
1 parent 988d0b7 commit 29ecd88

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,11 @@ trait Applications extends Compatibility {
13871387
// TODO: Maybe the 'reorder' method above can be reused, or be template
13881388
if (bunchedArgs != Nil && argTypes != Nil) {
13891389

1390-
val typeInfoOfGetMethod = unapplyFn.tpe.widen.asInstanceOf[MethodType].resType.member(nme.get).info
1390+
val typeInfoOfGetMethod =
1391+
if unapplyFn.tpe.widen.asInstanceOf[MethodType].resType.member(nme.get).exists then
1392+
unapplyFn.tpe.widen.asInstanceOf[MethodType].resType.member(nme.get).info
1393+
else
1394+
unapplyFn.tpe.widen.asInstanceOf[MethodType].resType
13911395

13921396
val names = typeInfoOfGetMethod
13931397
.memberDenots(typeNameFilter, (name, buf) => if (name.toString == "Names") buf += typeInfoOfGetMethod.member(name).asSingleDenotation)

compiler/test/dotty/tools/dotc/NamedPatternMatching.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ class NamedPatternMatching {
3737
).checkExpectedErrors()
3838
}
3939

40+
@Test def executionTest: Unit = {
41+
implicit val testGroup: TestGroup = TestGroup("runPos")
42+
aggregateTests(
43+
compileFile("tests/run/runNamedPatternMatching.scala", defaultOptions),
44+
).checkRuns()
45+
}
46+
4047
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Got name
2+
Got age
3+
Got city
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
object Test:
2+
3+
class User(val name: String, val age: Int, val city: String)
4+
5+
//TODO: Test this
6+
object UserEx:
7+
class UserExtractor(user: User) extends Product:
8+
def _1 = println("Got name"); user.name
9+
def _2 = println("Got age"); user.age
10+
def _3 = println("Got city"); user.city
11+
12+
type Names = ("name", "age", "city")
13+
14+
// Members declared in scala.Equals
15+
def canEqual(that: Any): Boolean = ???
16+
17+
// Members declared in scala.Product
18+
def productArity: Int = ???
19+
def productElement(n: Int): Any = ???
20+
21+
def unapply(user: User) = UserExtractor(user)
22+
23+
def main(args: Array[String]): Unit =
24+
val UserEx(city = _, name = _) = User("Guy", 25, "Paris")

0 commit comments

Comments
 (0)