Skip to content

Commit 7ce264b

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

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ trait TypeAssigner {
157157
else
158158
qualType.findMember(name, pre)
159159

160-
if reallyExists(mbr) then qualType.select(name, mbr)
160+
if reallyExists(mbr) && NamedType.validPrefix(qualType) then qualType.select(name, mbr)
161161
else if qualType.isErroneous || name.toTermName == nme.ERROR then UnspecifiedErrorType
162162
else NoType
163163
end selectionType

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)