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

Virtuals types #7576

Closed
scabug opened this issue Jun 13, 2013 · 4 comments
Closed

Virtuals types #7576

scabug opened this issue Jun 13, 2013 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jun 13, 2013

I have two class VA and VB. Each one contains abstract virtual parameter.
Other classes specialize this virtual parameter.
Is it correct, that my method foo(..).. of A1 takes a parameter of type B2 in this solution?
Thanks and best regards

class A1  extends VA{

  type TB=B1


}

class A2  extends VA{

  type TB=B2
}

class B1  extends VB{

  type TA=A1

}

class B2  extends VB{

  type TA=A2
}

object TMain  extends App {

  val a : VA = new A1()
  var b : VB = new B2()

  println(a.foo(b.asInstanceOf[a.TB]))

}

class VA{

  type TB <: VB
  var t : TB = _

  def foo(b : TB) : TB = {
    t = b
    return t
  }

}

class VB {

  type TA <: VA
}
@scabug
Copy link
Author

scabug commented Jun 13, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7576?orig=1
Reporter: kathykiseleva (ketud)
Affected Versions: 2.10.1
Attachments:

  • src.zip (created on Jun 13, 2013 3:05:52 PM UTC, 1503 bytes)

@scabug
Copy link
Author

scabug commented Jun 13, 2013

@paulp said (edited on Jun 13, 2013 5:46:17 PM UTC):
"asInstanceOf" means "I know what I'm doing." The method is not accepting a B2. You are lying and saying a B2 is the type it expects.

@scabug scabug closed this as completed Jun 13, 2013
@scabug
Copy link
Author

scabug commented Jun 14, 2013

kathykiseleva (ketud) said:
ok, execuse me, I am a begginer in scala:

if I understand good, it means that I can lie and it wouldn't be stopped even by executor. That's why I can execute this method with parameter of type B2...

because I've tested this:
val s : String = "abs"
val n : Int = 5
println(n + s.asInstanceOf[Int])
and during the execution it generates an error

thank you in advance

@scabug
Copy link
Author

scabug commented Jun 14, 2013

@paulp said:
That's correct, you can tell any lie you want and the compiler will believe it. As soon as you call "asInstanceOf", the compiler is off the hook.

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

No branches or pull requests

2 participants