Skip to content

Top level opaque type not transparent inside class in definition scope #18469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
prolativ opened this issue Aug 28, 2023 · 4 comments
Closed

Comments

@prolativ
Copy link
Contributor

Compiler version

3.4.0-RC1-bin-20230825-2616c8b-NIGHTLY and before

Minimized code

opaque type Foo = String

class Bar:
  val foo: Foo = "abc"

Output

[error] Opaque.scala:4:18
[error] Found:    ("abc" : String)
[error] Required: Foo
[error]   val foo: Foo = "abc"
[error]                  ^^^^^

Expectation

This should compile. Because Bar is defined in the same scope as Foo the definition of Foo should be transparent inside the body of Bar.

@prolativ prolativ added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:typer area:opaque-types and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 28, 2023
@prolativ
Copy link
Contributor Author

The problem doesn't occur if the snippet from above is moved to an object, e.g.

object Scope:
  opaque type Foo = String

  class Bar:
    val foo: Foo = "abc"

or if the opaque type is referenced from inside a top level method, e.g.

opaque type Foo = String

def bar =
  val foo: Foo = "abc"

so my assumption is that the problem is caused by the fact that the type gets moved to the synthetic package object but the scopes are compared for opaqueness/transparentness at a later point in the compilation pipeline

@prolativ
Copy link
Contributor Author

Possibly related to #18097

@som-snytt
Copy link
Contributor

#15050 has commentary

@bishabosha
Copy link
Member

bishabosha commented Aug 29, 2023

this is as specified, Foo is in the scope of the wrapping top-level-definition object for the file, and Bar is in its own top level scope. see the docs

@bishabosha bishabosha closed this as not planned Won't fix, can't repro, duplicate, stale Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants