Skip to content
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

Strange cyclic reference errors in complex inheritance source with opaque types #20414

Open
OndrejSpanel opened this issue May 15, 2024 · 0 comments
Labels
area:opaque-types area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement

Comments

@OndrejSpanel
Copy link
Member

Compiler version

3.4.1, 3.4.2, 3.5.0-RC1

Minimized example

object O {
  trait Types {
    export TypesOpaque.{ColorRGB, DataTexture}

    trait Encoder[T]

    implicit val colorRGBEncoder: Encoder[ColorRGB] = ???
  }

  trait TypesOpaqueBase {
    opaque type ColorRGB = LowLevel.Color

    opaque type DataTexture = LowLevel.Texture
  }

  object LowLevel {
    type Color = Int
    // type Texture = Unit
  }

  object TypesOpaque extends TypesOpaqueBase

  object TypesImpl extends Types
}

Output Error/Warning message

Not found: type ColorRGB
type Texture is not a member of object O.LowLevel
Cyclic reference involving type DataTexture
-- [E006] Not Found Error: cyclic.scala:7:42 -----------------------------------
7 |    implicit val colorRGBEncoder: Encoder[ColorRGB] = ???
  |                                          ^^^^^^^^
  |                                          Not found: type ColorRGB
  |
  | longer explanation available when compiling with `-explain`
-- [E008] Not Found Error: cyclic.scala:13:39 ----------------------------------
13 |    opaque type DataTexture = LowLevel.Texture
   |                              ^^^^^^^^^^^^^^^^
   |                       type Texture is not a member of object O.LowLevel
-- [E046] Cyclic Error: cyclic.scala:2:8 ---------------------------------------
2 |  trait Types {
  |        ^
  |        Cyclic reference involving type DataTexture
  |
  |         Run with -explain-cyclic for more details.
  |
  | longer explanation available when compiling with `-explain`
-- [E046] Cyclic Error: cyclic.scala:13:16 -------------------------------------
13 |    opaque type DataTexture = LowLevel.Texture
   |                ^
   |                Cyclic reference involving type DataTexture
   |
   |                 Run with -explain-cyclic for more details.
   |
   | longer explanation available when compiling with `-explain`
-- [E046] Cyclic Error: cyclic.scala:21:9 --------------------------------------
21 |  object TypesOpaque extends TypesOpaqueBase
   |         ^
   |         Cyclic reference involving type DataTexture
   |
   |          Run with -explain-cyclic for more details.
   |
   | longer explanation available when compiling with `-explain````

Why this Error/Warning was not helpful

There is a cyclic dependency involving type DataTexture reported, while in fact there is none, just a missing declaration.
There is type not found reported for type ColorRGB, but the type is defined OK.

This happened in a large project to me where I deleted declaration of type Texture = ... by mistake. The error about non-existent type Texture was drowned in about a hundred error messages about non-existent ColorRGB and other types exported by the same export.

When the opaque type DataTexture is replaced with just plain type DataTexture, the cyclic reference error no longer appears, but the error Not found: type ColorRGB is still present.

Suggested improvement

Report the missing type, do not report any cyclic dependency which is not there.

Note

When you remove the unused declaration of object TypesImpl extends Types, the error Not found: type ColorRGB no longer appears, which is also strange.

@OndrejSpanel OndrejSpanel added area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement stat:needs triage Every issue needs to have an "area" and "itype" label labels May 15, 2024
@Gedochao Gedochao added area:opaque-types and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:opaque-types area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Projects
None yet
Development

No branches or pull requests

2 participants