Skip to content

Commit a56c622

Browse files
Check if a prefix is valid before selecting from a type (#22368)
closes #22357 --------- Co-authored-by: Katarzyna Marek <[email protected]>
1 parent ddb4bd1 commit a56c622

File tree

6 files changed

+16
-1
lines changed

6 files changed

+16
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ trait TypeAssigner {
163163
else
164164
qualType.findMember(name, pre)
165165

166-
if reallyExists(mbr) then qualType.select(name, mbr)
166+
if reallyExists(mbr) && NamedType.validPrefix(qualType) then qualType.select(name, mbr)
167167
else if qualType.isErroneous || name.toTermName == nme.ERROR then UnspecifiedErrorType
168168
else NoType
169169
end selectionType

compiler/test/dotc/neg-best-effort-unpickling.excludelist

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ overrideClass.scala
1515

1616
# repeating <error> on a top level type definition
1717
i18750.scala
18+
19+
# Crash on invalid prefix ([A] =>> Int)
20+
i22357a.scala

tests/neg/i22357.check

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg/i22357.scala:1:0 -----------------------------------------------------------------------------------
2+
1 |@([A] =>> Int) // error
3+
|^^^^^^^^^^^^^^
4+
|[A] =>> Int does not have a constructor

tests/neg/i22357.scala

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@([A] =>> Int) // error
2+
def i = 1

tests/neg/i22357a.check

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg/i22357a.scala:2:6 ----------------------------------------------------------------------------------
2+
2 | new ([A] =>> Int)(2) // error
3+
| ^^^^^^^^^^^^^
4+
| [A] =>> Int does not have a constructor

tests/neg/i22357a.scala

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def main =
2+
new ([A] =>> Int)(2) // error

0 commit comments

Comments
 (0)