Skip to content

Commit

Permalink
Check if a prefix is valid before selecting from a type
Browse files Browse the repository at this point in the history
Co-Authored-By: Katarzyna Marek <[email protected]>
  • Loading branch information
KacperFKorban and kasiaMarek committed Jan 14, 2025
1 parent af655c9 commit 913c043
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ trait TypeAssigner {
else
qualType.findMember(name, pre)

if reallyExists(mbr) then qualType.select(name, mbr)
if reallyExists(mbr) && NamedType.validPrefix(qualType) then qualType.select(name, mbr)
else if qualType.isErroneous || name.toTermName == nme.ERROR then UnspecifiedErrorType
else NoType
end selectionType
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i22357.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/i22357.scala:1:0 -----------------------------------------------------------------------------------
1 |@([A] =>> Int) // error
|^^^^^^^^^^^^^^
|[A] =>> Int does not have a constructor
2 changes: 2 additions & 0 deletions tests/neg/i22357.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@([A] =>> Int) // error
def i = 1
4 changes: 4 additions & 0 deletions tests/neg/i22357a.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/i22357a.scala:2:6 ----------------------------------------------------------------------------------
2 | new ([A] =>> Int)(2) // error
| ^^^^^^^^^^^^^
| [A] =>> Int does not have a constructor
2 changes: 2 additions & 0 deletions tests/neg/i22357a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main =
new ([A] =>> Int)(2) // error

0 comments on commit 913c043

Please sign in to comment.