Skip to content

Fix crash on invalid opaque type in package - #26118

Merged
mbovel merged 4 commits into
scala:mainfrom
dotty-staging:solal/completer-crash
May 22, 2026
Merged

mbovel merged 4 commits into
scala:mainfrom
dotty-staging:solal/completer-crash

Conversation

@SolalPirelli

@SolalPirelli SolalPirelli commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #26089

How much have you relied on LLM-based tools in this contribution?

Not at all

How was the solution tested?

New automated tests (including the issue's reproducer, if applicable)

@SolalPirelli
SolalPirelli requested review from Gedochao and mbovel May 20, 2026 19:16

@mbovel mbovel left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am always wary of returning a default value when encountering an empty denotation/symbol/type/tree.

Any way we could directly report an error here, if we're sure this path is always erroneous?

@SolalPirelli
SolalPirelli requested a review from mbovel May 21, 2026 14:49
@SolalPirelli

Copy link
Copy Markdown
Contributor Author

Fair point, let's report an error explicitly, in fact it now looks better since it also means the "cyclic reference involving TestCases" no longer shows and that one was weird

@SolalPirelli
SolalPirelli force-pushed the solal/completer-crash branch from 250259c to 2a47946 Compare May 21, 2026 14:50
@mbovel

mbovel commented May 21, 2026

Copy link
Copy Markdown
Member

the "cyclic reference involving TestCases" no longer shows

Still seems to be in the checkfile?

@mbovel

mbovel commented May 21, 2026

Copy link
Copy Markdown
Member

I said orally this could maybe be a syntax error, but no, type T alone is a thing—bounds are implicitly Nothing..Any.

@mbovel

mbovel commented May 21, 2026

Copy link
Copy Markdown
Member

And I guess this example should actually pass if we have a type that takes a parameter instead of Int, shouldn't it? Could we have a test case for that as well?

@SolalPirelli

Copy link
Copy Markdown
Contributor Author

if we have a type that takes a parameter instead of Int

I'm not sure what you mean

@SolalPirelli

Copy link
Copy Markdown
Contributor Author

Still seems to be in the checkfile?

Ah yes, there were actually 2 of them before... so it's still not amazing.

@SolalPirelli
SolalPirelli force-pushed the solal/completer-crash branch from 2a47946 to 8a930ce Compare May 22, 2026 08:27
@SolalPirelli SolalPirelli added the needs-squashing PR whose commits should be squashed by the author or via the "Squash and Merge" button label May 22, 2026
@SolalPirelli

Copy link
Copy Markdown
Contributor Author

@mbovel you were right the parser is a much better place for this, see the new error message

@mbovel

mbovel commented May 22, 2026 •

Copy link
Copy Markdown
Member

if we have a type that takes a parameter instead of Int

I'm not sure what you mean

I mean this compiles:

type F[S] = S

trait I:
  type T: F

And I'd expect the opaque version to compile as well.
Why should opaque behave differently?
The type being opaque should not prevent declaring it conforms to a typeclass, should it?

At first sight, I'd say (current results on main):

type F[X] = X

trait I1:
  type T: F // works ✅
  opaque type S: F // crash, but should work

trait I2:
  type T: Int // error "Illegal context bound" ✅
  opaque type S: Int // crash, but should error

class C1:
  type T: F // error "No given instance of type F[C.this.T]" ✅
  opaque type S: F // crash, but should error

class C2:
  type T: Int // error "Illegal context bound" ✅
  opaque type S: Int // crash, but should error

class C3:
  given F[T] = ???
  type T: F // error "Conflicting definitions" 🤔
  opaque type S: F // crash, but should work or error

object O1:
  type T: F // error "Declaration of given instance given_F_T not allowed here" ✅
            // error "Conflicting definitions" 🤔
  opaque type S: F // crash, but should error

object O2:
  type T: Int // error "Illegal context bound" ✅
  opaque type S: Int // crash, but should error

@mbovel mbovel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can already merge to avoid the crash.
But longer-term, I think we should support opaque types with context bounds!

@mbovel
mbovel merged commit 4e44c38 into scala:main May 22, 2026
45 checks passed
@mbovel
mbovel deleted the solal/completer-crash branch May 22, 2026 12:28
@WojciechMazur WojciechMazur added this to the 3.9.0 milestone May 26, 2026
bishabosha pushed a commit to dotty-staging/dotty that referenced this pull request Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-squashing PR whose commits should be squashed by the author or via the "Squash and Merge" button

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhandled compiler exception when encountering invalid opaque type syntax inside a package

3 participants