Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if a prefix is valid before selecting from a type #22368

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions compiler/test/dotc/neg-best-effort-unpickling.excludelist
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ overrideClass.scala

# repeating <error> on a top level type definition
i18750.scala

# Crash on invalid prefix ([A] =>> Int)
i22357a.scala
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
Loading