Re: Compiler type inference problem?

I agree on that, but doesn't the 
def f() {}
construct means that the last statement is irrelevant, and the result type will always be Unit? And since Unit can be only Unit...
If I had used the = I would agree with you, but I didn't...
2012/2/3 √iktor Ҡlang <viktor [dot] klang [at] gmail [dot] com>


On Fri, Feb 3, 2012 at 3:01 PM, Dennis Haupt <h-star [at] gmx [dot] de> wrote:
unit is not a subclass of everything, so this error makes perfect sense.
to fix it:

               def example(space: Space) {
                       space.snapshot(new java.lang.Double(20d))
                       space.snapshot(new java.lang.Integer(30))
                       return

or simply: () 
               }

-------- Original-Nachricht --------
> Datum: Fri, 3 Feb 2012 11:39:12 +0100
> Von: Edmondo Porcu <edmondo [dot] porcu [at] gmail [dot] com>
> An: scala-user <scala-user [at] googlegroups [dot] com>
> Betreff: [scala-user] Compiler type inference problem?

> Dear all,
>
> look at the following case and why it doesn't compile:
>
> trait Generic[T]
> trait Space {
>   def snapshot[T](item:java.lang.Object):Generic[T]
> }
> class TypeInferenceProblem {
>
>   def example(space:Space){
>     space.snapshot(new java.lang.Double(20d))
>     space.snapshot(new java.lang.Integer(30))
>   }
>
> }
>
> error: polymorphic expression cannot be instantiated to expected type;
> found   : [T]com.gottex.scala.types.Generic[T]
> required: Unit
> space.snapshot(new java.lang.Integer(30))
>
>
> Whatever the return type of space.snapshot is, since the method will
> return
> unit, why does the compiler care?
>
> Best
>
> Edmondo



--
Viktor Klang

Akka Tech LeadTypesafe - The software stack for applications that scale

Twitter: @viktorklang

Copyright © 2013 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland