This page is no longer maintained — Please continue to the home page at www.scala-lang.org

2.8.0 - "method defined twice"

2 replies
Nicholas Tung
Joined: 2009-05-19,
User offline. Last seen 42 years 45 weeks ago.

Hi all,

The following code is rejected in 2.8.0 with "method gettype is defined twice". I'm using the maven snapshot builds, so they should be pretty recent.

def gettype(tpe : Type) : nodes.Type = gettype_inner(tpe)
def gettype(tree : Tree) : nodes.Type = gettype_inner(tree.tpe)

This is definitely supported in Java, and I thought it worked with some other Scala code I had...

Thanks in advance,
Nicholas
https://ntung.com

ewilligers
Joined: 2008-08-20,
User offline. Last seen 3 years 17 weeks ago.
Re: 2.8.0 - "method defined twice"

Nicholas Tung wrote:
> Hi all,
>
> The following code is rejected in 2.8.0 with "method gettype is
> defined twice". I'm using the maven snapshot builds, so they should be
> pretty recent.
>
> def gettype(tpe : Type) : nodes.Type = gettype_inner(tpe)
> def gettype(tree : Tree) : nodes.Type = gettype_inner(tree.tpe)
>
> This is definitely supported in Java, and I thought it worked with
> some other Scala code I had...

Overloading isn't possible if Type and Tree are erased to the same type.

There is no problem with the following:-

object nodes { type Type = Int }

abstract class TypeBase
abstract class TreeBase

class C {
type Type <: TypeBase
type Tree <: TreeBase

def gettype(tpe : Type) : nodes.Type = error("")
def gettype(tree : Tree) : nodes.Type = error("")
}

ounos
Joined: 2008-12-29,
User offline. Last seen 3 years 44 weeks ago.
Re: Re: 2.8.0 - "method defined twice"
Btw, I always liked the fact that the return type is part of the method signature in the VM. The following compiles and works fine (just as in Java):
 class X {   def a(list: List[Int]): Number = 5    def a(list: List[Double]): AnyRef = null }
2009/7/30 Eric Willigers <ewilligers [at] gmail [dot] com>
Nicholas Tung wrote:
Hi all,

  The following code is rejected in 2.8.0 with "method gettype is defined twice". I'm using the maven snapshot builds, so they should be pretty recent.

def gettype(tpe : Type) : nodes.Type = gettype_inner(tpe)
def gettype(tree : Tree) : nodes.Type = gettype_inner(tree.tpe)

  This is definitely supported in Java, and I thought it worked with some other Scala code I had...

Overloading isn't possible if Type and Tree are erased to the same type.

There is no problem with the following:-

object nodes { type Type = Int }

abstract class TypeBase
abstract class TreeBase

class C {
   type Type <: TypeBase
   type Tree <: TreeBase

   def gettype(tpe : Type) : nodes.Type = error("")
   def gettype(tree : Tree) : nodes.Type = error("")
}


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