English 中文(简体)
Weird Scala bug与默认建筑参数的默示转换有关
原标题:Weird Scala bug related to implicit conversions on default constructor parameters
  • 时间:2011-01-09 17:38:39
  •  标签:
  • scala

审议文件bug.scala:

package sandbox

object Foo {
  implicit def stringToInt(s: String) = 5
}

import Foo._

class Boo(val a: Int = "foo" / 3) {
  val b: Int = "foo" / 3
  def c(d: Int = "foo" / 3) = d
}

它界定了默示转换、进口,并在三种略有不同的情况下加以使用。 汇编:

E:progscala	est>scalac bug.scala
bug.scala:9: error: value / is not a member of java.lang.String
class Boo(val a: Int = "foo" / 3) {
                       ^
one error found

含蓄的转换似乎在用于违约构造参数时并不可行,而是用于其他假设情景。

现在看着:

package sandbox

object Foo {
  implicit def stringToInt(s: String) = 5
}

object dummy

import Foo._
import dummy._

class Boo(val a: Int = "foo" / 3) {
  val b: Int = "foo" / 3
  def c(d: Int = "foo" / 3) = d
}

我们只是添加了一个空洞的物体并进口了它。 如今,档案没有错误汇编!

我在此看到两种可能性: (1) 我的头指向我。 (2) 汇编者有ug。 谁能证实这一点?

(Using Scala 2.8.1.)

最佳回答

确切地说,这是ug。 我代表你提出。

https://issues.scala-lang.org/browse/SI-4141

问题回答

暂无回答




相关问题
How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

To use or not to use Scala for new Java projects? [closed]

I m impressed with Twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java? EDIT: And, ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

Scala and tail recursion

There are various answers on Stack Overflow which explain the conditions under which tail recursion is possible in Scala. I understand the limitations and how and where I can take advantage of tail ...

热门标签