-
Notifications
You must be signed in to change notification settings - Fork 3
Home
schauder edited this page Aug 17, 2011
·
11 revisions
In some cases it's possible to identify an accidentally left-off equals sign before a function body.
def sum(x: Int, y: Int) {
x + y //why on earth would we calculate this value if not to return it?
}
This is dead code that should result in a warning.
{
val (x,y,z) =triple
x + z
}
This is dead code that should result in a warning.
def method = {
val result = 3
+ 12
result
}
trait Foo {
def add(x : Int, y : Double) : Double
}
trait Bar extends Foo {
def add(y : int, x : Double) : Double
}
val x : Bar = ...
x.add(y = 1, x = 2) // Eh?
This one might need some kind of annotation on abstract values that require early initialization. If it's possible to detect solo, that'd rock.
trait Box {
val height : Int // This must be initialized 'early'
val width : Int // this must also be initialized 'early'
val area = height * width // This depends on height/width being available
val perimeter = 2*(height + width)
}
val x = new Box with {
val height = 1 // Error, not early enough
val width = 2
}
val y = new {
val height = 1 // WINNERS
val width = 2
} with Box
I can't define it properly, but I'll give an example
def implicit toString(any : Any) : String { .... }
def takesString(s : String) ={...}
object Obj{
def apply() : String = { ... }
}
takesString(Obj) // does an implicit conversion, possibly a bug
takesString(Obj()) // no implict conversion necessary, probably what was intended
Although Scala is mostly used on the JDK it is able to run on .NET which might fail when Java classes are used
http://stackoverflow.com/questions/1332574/common-programming-mistakes-for-scala-developers-to-avoid