Opaque types are not usable in the REPL under Java 9+
See original GitHub issueCompiler version
3.0.0-RC1
Minimized code
➜ scala3-repl
scala> opaque type Foo = Int
1 |opaque type Foo = Int
|^^^^^^
|Illegal start of statement: no modifiers allowed here
scala> object Module:
| opaque type Foo = Int
| object Foo:
| def fromInt(i: Int): Foo = i
|
// defined object Module
scala> import Module.*
scala> def bar(f: Foo) = println(f)
1 |def bar(f: Foo) = println(f)
| ^^^
| Not found: type Foo
scala> def bar(f: Module.Foo) = println(f)
1 |def bar(f: Module.Foo) = println(f)
| ^^^^^^^^^^
| type Foo is not a member of object Module
scala> :reset
scala> object Module:
| opaque type Foo = Int
| object Foo:
| def fromInt(i: Int): Foo = i
| def bar(f: Foo) = println(f)
| def baz = bar(42)
|
// defined object Module
Expectation
The top-level definition bug is tracked here: https://github.com/lampepfl/dotty/issues/9879
Not sure what’s going on with (1) inability to reference an opaque type defined in an object and (2) lack of opaque type enforcement in the last Module definition. Feels like something about the REPL encoding scheme is at odds with the opaque type implementation scheme.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Definitions in `java.lang._` shadow definitions in REPL · Issue ...
The current error messages are also not helpful to understand that those definitions are ... Opaque types are not usable in the REPL...
Read more >lampepfl/dotty - Gitter
When I try to use the library as it is in a Scala 2.13 project (org:lib_3.0.0-RC1:version) , it is not able to see...
Read more >Opaque Types — The Swift Programming Language (Swift 5.7)
A function or method with an opaque return type hides its return value's type information. Instead of providing a concrete type as the...
Read more >Algebras of opaque types and pattern matching
But there is a problem as we wish to design a developer friendly library, in that opaque types don't allow pattern matching. we...
Read more >6 Objects, Collections, and OPAQUE Types - Oracle Help Center
This chapter discusses how Oracle SQLJ supports user-defined SQL types--namely objects (and related object references) and collections (variable arrays and ...
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 Free
Top 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
Aha! It works for me when running RC1 REPL under Java 8 and fails on Java 9+
Wow, great find. I almost never use the word
Module
in Scala and just happened to do so here to work around #9879.