Opaque type weirdness: (self$proxy1 : Any) Required: BigDecimalNewType_this.Type
See original GitHub issueOpaque types possessing black magic.
It appears that adding 3 or more opaque type numeric causes the code to fail to compile. However here, uncommenting in Line 15 makes the code compile, which is odd, as it is seemingly a random opaque type declaration. Adding 2 Amounts
is fine, the issue appears when adding 3 Amounts
Compiler version
3.1.1
Minimized code
trait Newtype[Src]:
opaque type Type = Src
transparent trait BigDecimalNewType extends Newtype[BigDecimal]:
override opaque type Type = BigDecimal
inline def apply(inline dec: BigDecimal): Type = dec
extension (self: Type)
inline def value: BigDecimal = self
inline def +(inline y: Type): Type = self.value + y.value
type Amount = Amount.Type
object Amount extends BigDecimalNewType {
// opaque type Blahblahblah = BigDecimal
}
case class Fees(
exchange: Amount,
slippage: Amount,
bribe: Amount
):
def calculateTotalFees: Amount = exchange + slippage + bribe
@main def main(): Unit =
val fees: Fees = Fees(Amount(1),Amount(2), Amount(2))
val totalFees: Amount = fees.calculateTotalFees
println(s"totalFees: ${totalFees}")
Scastie link: https://scastie.scala-lang.org/MLbciD4bQtysh7mVlYy1ig
Output
Found: (self$proxy1 : Any)
Required: BigDecimalNewType_this.Type
Expectation
Compile regardless of Line 15 in the code.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Some keyword in Swift: Opaque types explained with code ...
The some keyword in Swift allows you to define opaque parameter and return types. Expose only minimum APIs without losing performance.
Read more >The Problem That Opaque Types Solve
An opaque type lets the function implementation pick the type for the value it returns in a way that's abstracted away from the...
Read more >Opaque Type Aliases
Opaque type aliases are type aliases that do not allow access to their underlying type outside of the file in which they are...
Read more >What defines an opaque type in C, and when are they ...
It is the most generally used for library purpose. The main principe behind Opaque type in c is to use data though its...
Read more >til / opaque types
This works by telling TypeScript that there exists a variable called $uuid that is a unique symbol (the result of calling Symbol() )...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Reduced further to:
Problem goes away if
inline
is dropped. Problem also exists ifinline
is replaced withtransparent inline
. Problem also goes away ifBigDecimalNewType
is changed to an object, as in:I’m wondering if what you’re trying to do here should be possible at all https://github.com/lampepfl/dotty/issues/14659