forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check New tree for ill-formed module instantiations
Fixes scala#17545
- Loading branch information
1 parent
4f3632f
commit 61190e6
Showing
9 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import scala.quoted.* | ||
|
||
object InvokeConstructor { | ||
inline def apply[A] = ${ constructorMacro[A] } | ||
|
||
def constructorMacro[A: Type](using Quotes) = { | ||
import quotes.reflect.* | ||
val tpe = TypeRepr.of[A] | ||
New(Inferred(tpe)).select(tpe.typeSymbol.primaryConstructor).appliedToArgs(Nil).asExprOf[A] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
case object WhateverA | ||
|
||
def testA = | ||
val whateverA: WhateverA.type = InvokeConstructor[WhateverA.type] // error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import scala.quoted.* | ||
|
||
object InvokeConstructor { | ||
inline def apply[A] = ${ constructorMacro[A] } | ||
|
||
def constructorMacro[A: Type](using Quotes) = { | ||
import quotes.reflect.* | ||
val tpe = TypeRepr.of[A] | ||
New(Inferred(tpe)).select(tpe.typeSymbol.primaryConstructor).appliedToArgs(Nil).asExprOf[A] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def testB = | ||
case object WhateverB | ||
val whateverB: WhateverB.type = InvokeConstructor[WhateverB.type] // error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import scala.quoted.* | ||
|
||
object InvokeConstructor { | ||
inline def apply[A] = ${ constructorMacro[A] } | ||
|
||
def constructorMacro[A: Type](using Quotes) = { | ||
import quotes.reflect.* | ||
val tpe = TypeRepr.of[A].termSymbol.moduleClass.typeRef | ||
New(Inferred(tpe)).select(tpe.typeSymbol.primaryConstructor).appliedToArgs(Nil).asExprOf[A] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
case object WhateverA | ||
|
||
def testA = | ||
val whateverA: WhateverA.type = InvokeConstructor[WhateverA.type] // error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import scala.quoted.* | ||
|
||
object InvokeConstructor { | ||
inline def apply[A] = ${ constructorMacro[A] } | ||
|
||
def constructorMacro[A: Type](using Quotes) = { | ||
import quotes.reflect.* | ||
val tpe = TypeRepr.of[A].termSymbol.moduleClass.typeRef | ||
New(Inferred(tpe)).select(tpe.typeSymbol.primaryConstructor).appliedToArgs(Nil).asExprOf[A] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def testB = | ||
case object WhateverB | ||
val whateverB: WhateverB.type = InvokeConstructor[WhateverB.type] // error |