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

fix tagFromTagMacro for scala.Array #520

Open
wants to merge 1 commit into
base: develop
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
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,15 @@ final class TagMacro(using override val qctx: Quotes) extends InspectorBase {
}

private def closestClassOfExpr(typeRepr: TypeRepr): Expr[Class[?]] = {
Literal(ClassOfConstant(lubClassOf(intersectionUnionRefinementClassPartsOf(typeRepr)))).asExprOf[Class[?]]
val arrayTypeSymbol = TypeRepr.of[Array].typeSymbol
Literal(
ClassOfConstant(
Copy link
Member

@pshirshov pshirshov Feb 12, 2025

Choose a reason for hiding this comment

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

While it might work as a workaround, I'm not inclined to accept this, as I said previously, this is a compiler bug which should be fixed in the compiler, and as far as I'm aware there is an open P/R fixing this. The bounty should either be removed from this issue or given to the compiler developers. /cc @jdegoes

Please consider other issues with bounties.

Copy link
Author

Choose a reason for hiding this comment

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

You can wait for compiler bug to resolve, or you make it work for your users and then wait for compiler bug to resolve. There is an issue with bounty and removing bounty after fix is done would be unfair

Copy link
Member

Choose a reason for hiding this comment

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

I've explained my position previously. The bounty shouldn't have been on this issue.

if typeRepr.baseClasses.contains(arrayTypeSymbol) then
TypeRepr.typeConstructorOf(classOf[Array[?]])
else
lubClassOf(intersectionUnionRefinementClassPartsOf(typeRepr))
)
).asExprOf[Class[?]]
}

private def lubClassOf(tpes: List[TypeRepr]): TypeRepr = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ class TagTest extends SharedTagTest with TagAssertions {
}

"Tag (Dotty)" should {
"Support Array tags" in {
case class Bar(bar: Int)
type Alias = Array[Byte]
object Opaque {
opaque type Type <: Array[Byte] = Array[Byte]
}

assertCompiles("Tag.tagFromTagMacro[Array[Byte]].tag")
assertCompiles("Tag.tagFromTagMacro[Array[Bar]].tag")
assertCompiles("Tag.tagFromTagMacro[Alias].tag")
assertCompiles("Tag.tagFromTagMacro[Opaque.Type].tag")
assertCompiles("Tag.tagFromTagMacro[Array].tag")
}

"Support union subtyping (Scala 3 specific, union types)" in {
trait Animal
Expand Down