Skip to content

Fix #4354: [BUG] mapTo fails to compile if case class is defined inside object#5377

Merged
adamw merged 5 commits into
softwaremill:masterfrom
dabrowski-adam:dabrowski-adam/4354
Jul 7, 2026
Merged

Fix #4354: [BUG] mapTo fails to compile if case class is defined inside object#5377
adamw merged 5 commits into
softwaremill:masterfrom
dabrowski-adam:dabrowski-adam/4354

Conversation

@dabrowski-adam

@dabrowski-adam dabrowski-adam commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Closes #4354

@dabrowski-adam dabrowski-adam changed the title Fix #4354: [BUG] Case class not found with mapInTo Fix #4354: [BUG] mapTo fails to compile if case class is defined inside object Jul 6, 2026
val tupleType = weakTypeOf[TUPLE]
val tupleTypeArgs = tupleType.dealias.typeArgs
if (caseClassUtil.fields.size == 0) {
q"(t: ${tupleType.dealias}) => ${caseClassUtil.className}()"

@dabrowski-adam dabrowski-adam Jul 6, 2026

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 went all in on supporting the companion object apply method, but I noticed that the Scala 3 code path doesn't use it and instead calls the constructor directly.

Should we align the Scala 2 implementation to use new?

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.

Let's keep the changes minimal to this bug. It is a discrepancy but not sure if it's worth fixing

@dabrowski-adam dabrowski-adam marked this pull request as ready for review July 6, 2026 18:10
lazy val companion: Tree = {
val name = TermName(t.typeSymbol.name.decodedName.toString)
t.dealias match {
case TypeRef(pre, _, _) if pre != NoPrefix => Select(c.internal.gen.mkAttributedQualifier(pre), name)

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.

will this work if there's a case class nested inside an object, and nested inside another object? That is, two levels deep? Maybe we should add such test

@adamw adamw merged commit ffd2ea4 into softwaremill:master Jul 7, 2026
16 checks passed
@adamw

adamw commented Jul 7, 2026

Copy link
Copy Markdown
Member

Great to have this fixed, thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] mapTo fails to compile if case class is defined inside object

2 participants