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.

companion extension method not found for opaque type

See original GitHub issue

Compiler version

v3.1.0-RC1

Minimized code

opaque type Foo[T] = Int
object Foo:
  extension [T](f: Foo[T]) def foo: Int = 1

def bar[T](f: Foo[T]): Unit =
  val x = f.foo

Output

value foo is not a member of Foo[T], but could be made available as an extension method.

Expectation

No error.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
oderskycommented, Sep 4, 2021

But it works if I put the whole thing in an object. So there’s still something wrong with the toplevel scope here.

object O:
  opaque type Foo[T] = Int
  object Foo:
    extension [T](f: Foo[T]) def foo: Int = 1

import O.*
def bar[T](f: Foo[T]): Unit =
  val x = f.foo
0reactions
soronpocommented, Oct 1, 2021

OK, I’ll submit a PR for the docs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Opaque Type Aliases - Scala 3 - EPFL
Opaque types aliases provide type abstraction without any overhead. ... None end Logarithm // Extension methods define opaque types' public APIs extension ...
Read more >
Opaque Type Aliases
Opaque types aliases provide type abstraction without any overhead. ... None end Logarithm // Extension methods define opaque types' public APIs extension ...
Read more >
Opaque Type Alias in Scala 3 - Baeldung
Let's add an extension method to the companion object of our opaque type Year: extension (year: Year) { def value: Int = year...
Read more >
scala - Top level opaque type with same underlying type and ...
I ran into an issue when defining opaque types with identical underlying types and extension methods, e.g.: opaque type HandleA = Int object ......
Read more >
Scala 3: Opaque Types - Rock the JVM Blog
We discover opaque type aliases in Scala 3 and how we can define new ... companion object) and “non-static” API (i.e. extension methods), ......
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