Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-10122

Type inference when inheriting class with non-public constructor

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: Scala 2.11.8, Scala 2.12.1
    • Fix Version/s: None
    • Component/s: Compiler (Misc)
    • Labels:
      None
    • Environment:

      Ubuntu 16.04

      Description

      cat inference/other/BaseClass.scala:

       
      package inference.other
      class BaseClass[T] protected(value: T)
      

      cat inference/Derived.scala

      package inference
      class Derived extends other.BaseClass("value")
      

      Compile:

      scalac inference/other/BaseClass.scala inference/Derived.scala 
      inference/Derived.scala:3: error: constructor BaseClass in class BaseClass cannot be accessed in package inference
       Access to protected constructor BaseClass not permitted because
       enclosing package inference is not a subclass of
       class BaseClass in package other where target is defined
      class Derived extends other.BaseClass("value")
                                  ^
      inference/Derived.scala:3: error: no arguments allowed for nullary constructor Object: ()Object
      class Derived extends other.BaseClass("value")
                                            ^
      two errors found
      

      If classes in the same package, everything is fine. If type parameter is specified extends other.BaseClass[String]("value") everything is also fine.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              dkomanov Dmitry Komanov
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: