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

Spurious illegal premature access to the unconstructed this error when using local methods inside a by-name closure in super-class constructor parameter #11969

Open
neko-kai opened this issue Apr 30, 2020 · 1 comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) should compile
Milestone

Comments

@neko-kai
Copy link

neko-kai commented Apr 30, 2020

reproduction steps

Minimized example:

package example

import scala.util.Try

class X(a: Any)

final class XImpl
  extends X({
    def res = Try(helper())

    def helper() = ()

    res
  })

problem

The above fails to compile with an error:

Error:(10, 19) Implementation restriction: access of method helper$1 from <$anon: Function0>, would require illegal premature access to the unconstructed `this` of class XImpl in package example
    def res = Try(helper())

However, the error can be worked around by enclosing the block in a redundant function with ().pipe { _ => ... }, in which case it will compile and work as expected at runtime:

package example

import scala.util.Try
import scala.util.chaining._

class X(a: Any)

final class XImpl
  extends X(().pipe { _ =>
    def res = Try(helper())

    def helper() = ()

    res
  })

Which shows that the code doesn't actually trigger an implementation restriction.

expectation

Expected it to compile. This bug affects classes that pass an effect value or a block of code to the superconstructor such as this. dotty is not affected.

@neko-kai
Copy link
Author

neko-kai commented Apr 30, 2020

Note: the above can also be worked around by making X's parameter by-name. However, there's another version of the bug that can't be worked around like that:

package example

class X(a: => Any)

class XImpl(
  param: Int
) extends X({
    def helper(): AutoCloseable = new AutoCloseable {
      def close() = println(param)
    }
    helper()
  })

Despite a: => Any this still does not compile:

Error:(9, 29) Implementation restriction: access of value param$1 from <$anon: AutoCloseable>, would require illegal premature access to the unconstructed `this` of <$anon: Function0>
      def close() = println(param)

But a pipe still works around it.

Dotty release was affected by the above bug, but it's fixed on master - scala/scala3#8846

@lrytz lrytz added this to the Backlog milestone May 4, 2020
neko-kai added a commit to 7mind/izumi that referenced this issue May 10, 2020
pshirshov pushed a commit to 7mind/izumi that referenced this issue May 13, 2020
neko-kai pushed a commit to 7mind/izumi that referenced this issue May 29, 2020
wip

activation as a field in PlannerInput

graph algos deprecated

cleanup

new planner: wip

new planner: wip

new planner: wip

all green

cleanups

cleanups

cleanups

cleanups

pre-resolution binding cleanup

old gc excluded from main codepath

cleanups

cleanups

cleanups

node remappings exposed

wip

wip

wip

cleanups

mutatorIndex in DIKey

implement Provider#replaceKeys

green tests

cleanups

some graph tests

minor cleanups

Make non-exhaustive pattern matches an error

fix neme-plugin cross-build

Build documentation in PRs

remove zio-RC16

cleanups

error on doc build failure

cleanup KeyMinimizer

cleanup

formatting

formatting

formatting

add failing activation tests, Rename PlannerInput.noGc->noGC, repurpose CglibBootstrap, document new Activation behavior,

MutatorSyntax: Add ModuleDef DSL `modify` and `make.from[X].modify` methods

Switch to `ProviderMagnet => ProviderMagnet` formulation

wip

wip

green mutator test

wip

all green

compilation fixed

tailrec conflict tracer

possible fix for zip fs race issue

reorder method precedence in MutationResolver

Implement bootstrap circular dependencies config using axis (need to remove tag merging for it to work though)

wip remove tagwise merge

Add `DIResource.OfInner` as a workaround for scala/bug#11969, add `DIResource.SelfOf`,`.MutableOf`

wip fix after removing tag merge, wip new distage.Injector api

vector

cleanups

more data for conflict resolver

conflict resolver made aware of weak edges

doc

docs: wip

fix

fixes

all green

fixes

fixes

Add ModuleBase.tagged, .untagged, .removeTags, make Binding.withTag public

rename `Docker.Mount` parameter names
neko-kai pushed a commit to 7mind/izumi that referenced this issue Jul 7, 2020
wip

activation as a field in PlannerInput

graph algos deprecated

cleanup

new planner: wip

new planner: wip

new planner: wip

all green

cleanups

cleanups

cleanups

cleanups

pre-resolution binding cleanup

old gc excluded from main codepath

cleanups

cleanups

cleanups

node remappings exposed

wip

wip

wip

cleanups

mutatorIndex in DIKey

implement Provider#replaceKeys

green tests

cleanups

some graph tests

minor cleanups

Make non-exhaustive pattern matches an error

fix neme-plugin cross-build

Build documentation in PRs

remove zio-RC16

cleanups

error on doc build failure

cleanup KeyMinimizer

cleanup

formatting

formatting

formatting

add failing activation tests, Rename PlannerInput.noGc->noGC, repurpose CglibBootstrap, document new Activation behavior,

MutatorSyntax: Add ModuleDef DSL `modify` and `make.from[X].modify` methods

Switch to `ProviderMagnet => ProviderMagnet` formulation

wip

wip

green mutator test

wip

all green

compilation fixed

tailrec conflict tracer

possible fix for zip fs race issue

reorder method precedence in MutationResolver

Implement bootstrap circular dependencies config using axis (need to remove tag merging for it to work though)

wip remove tagwise merge

Add `DIResource.OfInner` as a workaround for scala/bug#11969, add `DIResource.SelfOf`,`.MutableOf`

wip fix after removing tag merge, wip new distage.Injector api

vector

cleanups

more data for conflict resolver

conflict resolver made aware of weak edges

doc

docs: wip

fix

fixes

all green

fixes

fixes

Add ModuleBase.tagged, .untagged, .removeTags, make Binding.withTag public

rename `Docker.Mount` parameter names
neko-kai added a commit to 7mind/izumi that referenced this issue Jul 7, 2020
* 0.11.0 Mutators

wip

activation as a field in PlannerInput

graph algos deprecated

cleanup

new planner: wip

new planner: wip

new planner: wip

all green

cleanups

cleanups

cleanups

cleanups

pre-resolution binding cleanup

old gc excluded from main codepath

cleanups

cleanups

cleanups

node remappings exposed

wip

wip

wip

cleanups

mutatorIndex in DIKey

implement Provider#replaceKeys

green tests

cleanups

some graph tests

minor cleanups

Make non-exhaustive pattern matches an error

fix neme-plugin cross-build

Build documentation in PRs

remove zio-RC16

cleanups

error on doc build failure

cleanup KeyMinimizer

cleanup

formatting

formatting

formatting

add failing activation tests, Rename PlannerInput.noGc->noGC, repurpose CglibBootstrap, document new Activation behavior,

MutatorSyntax: Add ModuleDef DSL `modify` and `make.from[X].modify` methods

Switch to `ProviderMagnet => ProviderMagnet` formulation

wip

wip

green mutator test

wip

all green

compilation fixed

tailrec conflict tracer

possible fix for zip fs race issue

reorder method precedence in MutationResolver

Implement bootstrap circular dependencies config using axis (need to remove tag merging for it to work though)

wip remove tagwise merge

Add `DIResource.OfInner` as a workaround for scala/bug#11969, add `DIResource.SelfOf`,`.MutableOf`

wip fix after removing tag merge, wip new distage.Injector api

vector

cleanups

more data for conflict resolver

conflict resolver made aware of weak edges

doc

docs: wip

fix

fixes

all green

fixes

fixes

Add ModuleBase.tagged, .untagged, .removeTags, make Binding.withTag public

rename `Docker.Mount` parameter names

* fix build

* forward-port fix for DistageTestRunner from feature/mutator-syntax-before-squash

* Feature/add replace parameter ids on binding for mutator syntax (#1088)

* wip

* small clean up

* fix

* use modify syntax instead of SetParameterId

* fixes

* throw if new modified provider returns an incompatible type

* Use magnet instead of partially applied class. (#1090)

* Add ContractedId[I], use it everywhere.

* Add ContactedId into missed functions. Remove unnecessary method.

* Remove type parameter from ContractedId, rename to `Identifier`

* Fix `namedByImpl` (but break its previous incorrect behaviour)

* Uncomment `modify`, Remove duplication in dsl, lift restriction on `.aliased` being final modifier only due to operation sorting

* WIP conflict resolution better error rendering

* warning fixes

Co-authored-by: Pavel Shirshov <[email protected]>
Co-authored-by: Alex Liubymov <[email protected]>
@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) should compile
Projects
None yet
Development

No branches or pull requests

4 participants