question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

newtype extending newtype when underlying values extend eachother?

See original GitHub issue

Given:

trait Foo
trait Bar extends Foo

why wouldn’t

@newtype class NFoo(val internal: Foo)
@newtype class NBar(override val internal: Bar) extends NFoo(internal)

be valid?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
s5bugcommented, Jun 2, 2020

Here’s how it might be expanded:

type NFoo = NFoo.Type
object NFoo {
  type Repr = Foo
  type Base = Any { type NFoo$newtype }
  trait Tag extends Any
  type Type <: Base with Tag
  implicit final class Ops$newtype(val $this$: Type) extends AnyVal {
    def internal: Foo = $this$.asInstanceOf[Foo]
  }
}

type NBar = NBar.Type
object NBar {
  type Repr = Bar
  type Base = Any { type NBar$newtype }
  trait Tag extends Any
  type Type <: NFoo.Type with Base with Tag
  implicit final class Ops$newtype(val $this$: Type) extends AnyVal {
    def internal: Bar = $this$.asInstanceOf[Bar]
  }
}

My only worry is the internals conflicting; depending on how implicit priority works, NBar.Ops$newtype should take priority over NFoo.Ops$newtype.

0reactions
carymrobbinscommented, Jun 13, 2020

I think so; try adding the <: Foo bound on my previous example -

@newtype case class N[+A <: Foo](internal: T forSome { type T <: A })
Read more comments on GitHub >

github_iconTop Results From Across the Web

Extending the Type System - Polyglot Tutorial
Every interface defining a type and its operations ultimately extends Type . ... Typically, a new type class can be defined by extending...
Read more >
https://svn.python.org/projects/python/branches/re...
This is not hard; the code for all extension types follows a pattern, ... So, if you want to define a new object...
Read more >
Possible to extend types in Typescript? - Stack Overflow
UPDATE for TypeScript 2.2, it's now possible to have an interface that extends object-like type, if the type satisfies some restrictions:
Read more >
Chapter 6. Using Typeclasses - Real World Haskell
Typeclasses are at the heart of some basic language features such as equality ... As with the data keyword, we can use a...
Read more >
Extending the model · Backstage Software Catalog and ...
Adding a new type takes relatively little effort and carries little risk. Any type value is accepted by the catalog backend, but plugins...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found