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

leaking of local parameter of dependent method type #7084

Open
scabug opened this issue Feb 5, 2013 · 2 comments
Open

leaking of local parameter of dependent method type #7084

scabug opened this issue Feb 5, 2013 · 2 comments
Labels
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Feb 5, 2013

object Test {
  trait A { a =>
    type X
    val x: a.X
  }
  val a = new A {
    type X = Int
    val x = 1
  }
  def f(arg: A): arg.X = arg.x
  val x = f(a: A)
}

snippet from -Xprint:typer:

...
    private[this] val x: arg.X = Test.this.f((Test.this.a: Test.A));
    <stable> <accessor> def x: arg.X = Test.this.x
...

arg is not in scope...

I don't know yet how to turn this into a true soundness issue, but it's weird.

@scabug
Copy link
Author

@scabug scabug commented Feb 5, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7084?orig=1
Reporter: @namin
See #3873

@scabug
Copy link
Author

@scabug scabug commented Feb 5, 2013

@retronym said:
Reflecting my way to the same conclusions as you reached:

scala> :power
Already in power mode.

scala> val u = rootMirror.universe; import u._, language._, intp.deconstruct.showu: u.type = scala.tools.nsc.interpreter.IMain$$anon$1@4a2e2b5c
import u._
import language._
import intp.deconstruct.show

scala> object Foo { trait A { type X }; def id(a: A): a.X = ???; def foo = id(??? : A) } 
defined module Foo

scala> val fooTpe = typeOf[Foo.type].decl(newTermName("foo")).tpe.resultType
fooTpe: u.Type = a.X

scala> val aSym = fooTpe.prefix.asInstanceOf[SingleType].sym
aSym: u.Symbol = value a

scala> aSym.isValueParameter
res62: Boolean = true

scala> aSym.owner
res63: u.Symbol = method id

I was also unable to poke a soundness hole:

object Foo {
  trait A { trait X { type A; def f(a: A); val a: A }; def X: X };
  object i extends A { object X extends super.X { type A = Int; def f(a: Int) = (); val a = 0 } };
  object s extends A { object X extends super.X { type A = String; def f(a: String) = (); val a = "" } };

  def id(a: A): a.X = a.X
  val x = id(i : A) // x: a.X

  id(i : A).f(id(s : A).a)
  // <console>:47: error: type mismatch;
  // found   : a.X#A
  // required: _31.A where val _31: a.X
  //            id(i : A).f(id(s : A).a)
}

This commit to InstantiateDependentMap is work a look:

scala/scala@b40f4ba322

@scabug scabug added the infer label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant