Skip to content

Commit 089a90a

Browse files
committed
Add accessiblity test
1 parent a5e4145 commit 089a90a

File tree

3 files changed

+49
-18
lines changed

3 files changed

+49
-18
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ trait Applications extends Compatibility {
12591259
* whereas overloaded variants need to have a conforming variant.
12601260
*/
12611261
def trySelectUnapply(qual: untpd.Tree)(fallBack: (Tree, TyperState) => Tree): Tree = {
1262-
// try first for non-overloaded, then for overloaded ocurrences
1262+
// try first for non-overloaded, then for overloaded occurrences
12631263
def tryWithName(name: TermName)(fallBack: (Tree, TyperState) => Tree)(using Context): Tree = {
12641264
def tryWithProto(pt: Type)(using Context) = {
12651265
val result = typedExpr(untpd.Select(qual, name), new UnapplyFunProto(pt, this))
@@ -1394,6 +1394,7 @@ trait Applications extends Compatibility {
13941394
resTypeOfUnapplyFn.member(nme.get).info
13951395
.orElse(resTypeOfUnapplyFn)
13961396
.member(tpnme.Names)
1397+
.accessibleFrom(selType)
13971398
// TODO: Is it possible to get something else than a SingleDenotation?
13981399
.asSingleDenotation
13991400

@@ -2141,7 +2142,7 @@ trait Applications extends Compatibility {
21412142
mappedSym.rawParamss = alt.symbol.rawParamss
21422143
// we need rawParamss to find parameters with default arguments,
21432144
// but we do not need to be precise right now, since this is just a pre-test before
2144-
// we look up defult getters. If at some point we extract default arguments from the
2145+
// we look up default getters. If at some point we extract default arguments from the
21452146
// parameter symbols themselves, we have to find the right parameter by name, not position.
21462147
// That means it's OK to copy parameters wholesale rather than tailoring them to always
21472148
// correspond to the type transformation.
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
-- Error: tests/neg/negNamedPatternMatching.scala:18:20 ----------------------------------------------------------------
2-
18 | case User(names = "Tom", city = city) => ??? // error
1+
-- Error: tests/neg/negNamedPatternMatching.scala:43:20 ----------------------------------------------------------------
2+
43 | case User(names = "Tom", city = city) => null // error
33
| ^^^^^
44
| 'names' is unknown
5-
-- Error: tests/neg/negNamedPatternMatching.scala:19:22 ----------------------------------------------------------------
6-
19 | case User(city = _, 10) => null // error
5+
-- Error: tests/neg/negNamedPatternMatching.scala:44:22 ----------------------------------------------------------------
6+
44 | case User(city = _, 10) => null // error
77
| ^^
88
| Only named arguments allowed here
9-
-- Error: tests/neg/negNamedPatternMatching.scala:20:18 ----------------------------------------------------------------
10-
20 | case User(age = Age(years = 10)) => null // error
9+
-- Error: tests/neg/negNamedPatternMatching.scala:45:18 ----------------------------------------------------------------
10+
45 | case User(age = Age(years = 10)) => null // error
1111
| ^^^
1212
| 'patterns.Age' doesn't support named patterns
13-
-- Error: tests/neg/negNamedPatternMatching.scala:23:11 ----------------------------------------------------------------
14-
23 | name = "Tom 2", // error
13+
-- Error: tests/neg/negNamedPatternMatching.scala:48:11 ----------------------------------------------------------------
14+
48 | name = "Tom 2", // error
1515
| ^^^^^^^
1616
| 'name' was already used before
17-
-- Error: tests/neg/negNamedPatternMatching.scala:24:11 ----------------------------------------------------------------
18-
24 | name = "Tom 3" // error
17+
-- Error: tests/neg/negNamedPatternMatching.scala:49:11 ----------------------------------------------------------------
18+
49 | name = "Tom 3" // error
1919
| ^^^^^^^
2020
| 'name' was already used before
21-
-- Error: tests/neg/negNamedPatternMatching.scala:26:22 ----------------------------------------------------------------
22-
26 | case User(_, name = "Anna") => null // error
21+
-- Error: tests/neg/negNamedPatternMatching.scala:51:22 ----------------------------------------------------------------
22+
51 | case User(_, name = "Anna") => null // error
2323
| ^^^^^^
2424
| name was already used as a positional pattern
25+
-- Error: tests/neg/negNamedPatternMatching.scala:52:19 ----------------------------------------------------------------
26+
52 | case User(city = City(name = "Berlin")) => null // error
27+
| ^^^^
28+
| 'patterns.City' doesn't support named patterns

tests/neg/negNamedPatternMatching.scala

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,43 @@ object Age:
1010
def unapply(age: Age): Some[Int] =
1111
Some(age)
1212

13-
case class User(name: String, age: Age, city: String)
13+
type City = City.City
1414

15-
val user = User(name = "Anna", age = Age(10), city = "Berlin")
15+
object City:
16+
opaque type City = String
17+
18+
class ExCity(city: City) extends Product:
19+
def _1: String = city
20+
21+
private[City] type Names = "name" *: EmptyTuple
22+
23+
// Members declared in scala.Equals
24+
def canEqual(that: Any): Boolean = ???
25+
26+
// Members declared in scala.Product
27+
def productArity: Int = ???
28+
def productElement(n: Int): Any = ???
29+
30+
City("test") match
31+
case City("test") => null
32+
case _ => null
33+
34+
def apply(name: String): City = name
35+
36+
def unapply(age: City): ExCity = ExCity(age)
37+
38+
case class User(name: String, age: Age, city: City)
39+
40+
val user = User(name = "Anna", age = Age(10), city = City("Berlin"))
1641

1742
val annasCity = user match
18-
case User(names = "Tom", city = city) => ??? // error
43+
case User(names = "Tom", city = city) => null // error
1944
case User(city = _, 10) => null // error
2045
case User(age = Age(years = 10)) => null // error
2146
case User(
2247
name = "Tom",
2348
name = "Tom 2", // error
2449
name = "Tom 3" // error
2550
) => null
26-
case User(_, name = "Anna") => null // error
51+
case User(_, name = "Anna") => null // error
52+
case User(city = City(name = "Berlin")) => null // error

0 commit comments

Comments
 (0)