Skip to content

Emit generic signatures for all trait fields#25780

Merged
tanishiking merged 7 commits into
scala:mainfrom
dotty-staging:solal/trait-field-generic-signature
Apr 21, 2026
Merged

Emit generic signatures for all trait fields#25780
tanishiking merged 7 commits into
scala:mainfrom
dotty-staging:solal/trait-field-generic-signature

Conversation

@SolalPirelli
Copy link
Copy Markdown
Contributor

@SolalPirelli SolalPirelli commented Apr 14, 2026

Part of #24275
Fixes #6350

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

not

How was the solution tested?

issue reproducer as automated test

@SolalPirelli SolalPirelli added the needs-squashing PR whose commits should be squashed by the author or via the "Squash and Merge" button label Apr 14, 2026
// since that information never existed.
// Thus, we first check if the symbol was specifically marked as having generic information,
if sym.is(MixedIn) then mixinPhase.asInstanceOf[Mixin].mixinGenericInfos.get(sym) match
mixinPhase.asInstanceOf[Mixin].mixinGenericInfos.get(sym) match
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Adding MixedIn to everything that's mixed in causes so many tests to fail... and is not necessary here anyway

private object PrivateObject
}

object Test extends T
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

regression test for some crashes while developing this

Copy link
Copy Markdown
Member

@tanishiking tanishiking left a comment

Choose a reason for hiding this comment

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

The approach looks good 👍 while module class bar$ is fixed, the class bar's generic signature is not yet fixed.

Comment on lines +17 to +20
classOf[bar.type].getMethods.sortBy(_.getName).filter(_.getName.contains("foo")).foreach(m => {
println(m)
println(m.toGenericString)
})
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.

How about Class.forName("bar") ? The generic signature for bar.foo() seems still a raw type based on javap (above is testing for bar$).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed... There's a whole separate way to create generic signatures for mirror classes. I've spent ~10h trying to fix this and gone nowhere because the interaction of erasure and mixins means we fundamentally have incorrect information once we reach the backend, so we end up in cases where descriptors and generic signatures diverge in ways that aren't correct, e.g., the gensig has String where the descriptor has Object.

I suggest we open an issue and accept this for now.

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.

Hmm, for Java interop, the relevant entry point is bar.foo() static forwarder, not bar$.foo(). If the generic signature for bar.foo() remains raw type, I think we should keep #24275 open for tracking the issue.
On the other hand, this PR seems fixing #6350 ? We might wanna add a test for #6350, merge this PR and close it, and keep #24275 open?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(I've changed the description to say "part of #24275" instead of "fixes")

@SolalPirelli SolalPirelli force-pushed the solal/trait-field-generic-signature branch from abea633 to 7423013 Compare April 21, 2026 07:11
Copy link
Copy Markdown
Member

@tanishiking tanishiking left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

public void Bar.Foo$_setter_$foo_$eq(scala.Option)
public void Bar.Foo$_setter_$foo_$eq(scala.Option<java.lang.String>)
public scala.Option Bar.foo()
public scala.Option<java.lang.String> Bar.foo()
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.

❤️

@tanishiking tanishiking enabled auto-merge (squash) April 21, 2026 07:58
@tanishiking tanishiking merged commit 8a32c2e into scala:main Apr 21, 2026
45 checks passed
mbovel pushed a commit to mbovel/dotty that referenced this pull request May 4, 2026
Part of scala#24275
Fixes scala#6350 

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

not

## How was the solution tested?

issue reproducer as automated test
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.

No generic signature emitted for trait getter

2 participants