Skip to content

Opaque types are not visible when referenced by package #20038

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
scf37 opened this issue Mar 28, 2024 · 3 comments
Closed

Opaque types are not visible when referenced by package #20038

scf37 opened this issue Mar 28, 2024 · 3 comments

Comments

@scf37
Copy link

scf37 commented Mar 28, 2024

Compiler version

3.4.0

Minimized code

package foo

opaque type Bar = bar.Bar

object bar:
  class Bar()

  object Bar:
    def apply(): foo.Bar =
      new Bar()

Output

[error] 10 |      new Bar()
[error]    |      ^^^^^^^^^
[error]    |    Found:    foo.bar.Bar
[error]    |    Required: foo.Bar²
[error]    |
[error]    |    where:    Bar  is a class in object bar
[error]    |              Bar² is a type in the top-level definitions in package foo
[error]    |
[error]    | longer explanation available when compiling with `-explain`

Expectation

Successful compilation since bar.Bar.apply is in scope of opaque type foo.Bar

@scf37 scf37 added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 28, 2024
@som-snytt
Copy link
Contributor

som-snytt commented Mar 28, 2024

Duplicates #19609

I'll leave this open since the other PR is not merged. (So I can't test it to be sure.)

@Gedochao Gedochao added area:opaque-types stat:duplicate and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 2, 2024
@sjrd
Copy link
Member

sjrd commented Apr 2, 2024

I don't think this is a duplicate.

This is as designed, AFAICT. The top-level opaque type desugars into being a member of a "package object", as per the spec of top-level definitions. So it is equivalent to

package foo

object FileName$package {
  opaque type Bar = bar.Bar
}

object bar:
  class Bar()

  object Bar:
    def apply(): foo.FileName$package.Bar =
      new Bar()

and now it's clear that Bar.apply is not within the private scope of FileName$package where the opaque type alias would be transparent.

@Gedochao
Copy link
Contributor

Gedochao commented Apr 2, 2024

Thanks for the clarification @sjrd.
Closing this, as this works as intended.

@Gedochao Gedochao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2024
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

4 participants