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.

Regression: class with no object shadows outer object

See original GitHub issue

Compiler version

3.0.0-RC1

Minimized code

sealed trait Children
object Children {
  sealed trait None extends Children
  sealed trait Varargs extends Children
}

sealed abstract class CtorType {
  type ChildrenType <: Children
}

object CtorType {
  final class X() extends CtorType {
    override type ChildrenType = Children.None
  }

  final class Children() extends CtorType {
    override type ChildrenType = Children.Varargs
  }
}

Output

-- Error: x.scala:13:33 --------------------------------------------------------
13 |    override type ChildrenType = Children.None
   |                                 ^^^^^^^^
   |        Reference to creator proxy for class Children in object CtorType
   |        shadows outer reference to object Children
-- Error: x.scala:17:33 --------------------------------------------------------
17 |    override type ChildrenType = Children.Varargs
   |                                 ^^^^^^^^
   |        Reference to creator proxy for class Children in object CtorType
   |        shadows outer reference to object Children
2 errors found

Expectation

It should compiles as it does in Scala 2.x.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Jasper-Mcommented, Mar 23, 2021

But “constructor proxy companions cannot be used as values by themselves”.

The documentation also says:

Scala case classes generate apply methods, so that values of case classes can be created using simple function application, without needing to write new.

Scala 3 generalizes this scheme to all concrete classes.

It’s nice that Scala 3 thinks of the poor StackOverflow answerers who came in after all the high-reputation answers were already taken. Some nice generalizations with just enough differences to thoroughly confuse people should do the trick.

1reaction
som-snyttcommented, Mar 23, 2021

The bug may be where the spec turns to their date in the darkened theater and whispers with menacing assurance:

and there is also no other value or method named C defined or inherited in the scope where C is defined.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resolve the error "outer reference shadow" while ...
How to resolve the error "outer reference shadow" while referring to another object within the class in Scala? - Stack Overflow. Stack Overflow ......
Read more >
Cannot instantiate local class whose name shadows outer ...
I have a source file defining a class A. A second file would like to demonstrate a small variation of A, not enough...
Read more >
Create Instance of Outer Class When Inner Class Shadows ...
When I execute new A(); in anonymous window, I get inner class printed, but I need the instance of outer B1 class. One...
Read more >
Chapter 6
Now we can extend our discussion of the design of classes and objects ... These activities are not strictly linear – they overlap...
Read more >
Activity 4 - Shadow Tracing
Summary: The class will measure their shadow lengths outside three times ... Objective 3.01 Observe that light travels in a straight line until...
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