- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
[2.8] cannot override a concrete member without a third member that's overridden by both
Tue, 2009-12-15, 12:22
Part of my code that compiles fine against 2.7.7 fails to do so
against 2.8 beta rc1.
I am using Nathan's dispatch library, and I have built a way to
override status errors/exceptions. Specifically:
import dispatch._
private[riakka] trait WhenAware {
def when[T](check: Int => Boolean)(handler: Handler[T]): T
}
/* This behaviour gives us fine-grained control on dealing with
low-level exceptions */
private[riakka] trait RiakkaExceptionHandler extends WhenAware {
abstract override def when[T](check: Int => Boolean)(handler:
Handler[T]): T = {
try {
super.when(check)(handler)
} catch {
case StatusCode(304, _) => throw NotModified
case StatusCode(404, _) => throw new NoSuchElementException
}
}
}
abstract class RiakkaException extends RuntimeException
object NotModified extends RiakkaException
and in my client code I initialize Http mixing in this trait:
private def http = new Http with RiakkaExceptionHandler
I get:
[info] Compiling main sources...
[error] /Users/ftreacy/Documents/work/projects/riakka/src/main/scala/Riakka.scala:20:
overriding method when in class Http of type [T](chk: (Int) =>
Boolean)(hand: dispatch.Handler[T])T;
[error] method when in trait RiakkaExceptionHandler of type
[T](check: (Int) => Boolean)(handler: dispatch.Handler[T])T cannot
override a concrete member without a third member that's overridden by
both (this rule is designed to prevent ``accidental overrides'')
[error] private def http = new Http with RiakkaExceptionHandler
[error] ^
[error] one error found
I seriously cannot decode that message "cannot override a concrete
member without a third member that's overridden by both". What should
I do to make the compiler happy?
Thanks,
Francisco
Thu, 2009-12-17, 10:27
#2
Re: Re: [2.8] cannot override a concrete member without a thir
Try making WhenAware have a self type of Http, or maybe just outright
extend Http.
Thu, 2009-12-17, 10:47
#3
Re: Re: [2.8] cannot override a concrete member without a thir
See #2497 (https://lampsvn.epfl.ch/trac/scala/ticket/2497) that's
where the error message was introduced. As I understand it, it should
prevent accidental overriding by mixing in traits.
But in your case something seems odd with the rules. You can even
leave WhenAware completely aside and get the same error. Here, I tried
an even simplier case:
class X {
def test(i:Int):String = i.toString
}
trait ConstantTestImpl { self:X =>
override def test(i:Int):String = "test"
}
(new X with ConstantTestImpl)
:7: error: overriding method test in class X of type (i: Int)String;
method test in trait ConstantTestImpl of type (i: Int)String cannot
override a concrete member without a third member that's overridden by
both (this rule is designed to prevent ``accidental overrides'')
(new X with ConstantTestImpl)
^
This case is different from the one in #2497 in that it actually
defines the self-type and has the override modifier to flag what it
should do. This seems like a very common use case for traits and
should flag errors and many other projects.
For now, the best workaround would be to use:
private[riakka] trait RiakkaExceptionHandler extends Http /*with WhenAware */ {
Johannes
On Thu, Dec 17, 2009 at 10:07 AM, francisco treacy
wrote:
> Hi, could anybody please give me a hint? :) or maybe point me to a
> migration guide if such thing exists?
>
>> cannot override a concrete member without a third member that's overridden by both
>
> concrete member = new Http
> third member = some trait that both RiakkaExceptionHandler and Http mix in (?)
>
> But in that case, it wouldn't be feasible. I don't have access to tell
> Http what it should mix in.
>
>> this rule is designed to prevent ``accidental overrides''
>
> Btw, couldn't it have been a warning instead of an error?
>
> Thanks!
>
> Francisco
>
>
>
>
> 2009/12/15 francisco treacy :
>> Part of my code that compiles fine against 2.7.7 fails to do so
>> against 2.8 beta rc1.
>>
>> I am using Nathan's dispatch library, and I have built a way to
>> override status errors/exceptions. Specifically:
>>
>> import dispatch._
>>
>> private[riakka] trait WhenAware {
>> def when[T](check: Int => Boolean)(handler: Handler[T]): T
>> }
>>
>> /* This behaviour gives us fine-grained control on dealing with
>> low-level exceptions */
>> private[riakka] trait RiakkaExceptionHandler extends WhenAware {
>> abstract override def when[T](check: Int => Boolean)(handler:
>> Handler[T]): T = {
>> try {
>> super.when(check)(handler)
>> } catch {
>> case StatusCode(304, _) => throw NotModified
>> case StatusCode(404, _) => throw new NoSuchElementException
>> }
>> }
>> }
>>
>> abstract class RiakkaException extends RuntimeException
>> object NotModified extends RiakkaException
>>
>> and in my client code I initialize Http mixing in this trait:
>>
>> private def http = new Http with RiakkaExceptionHandler
>>
>> I get:
>>
>> [info] Compiling main sources...
>> [error] /Users/ftreacy/Documents/work/projects/riakka/src/main/scala/Riakka.scala:20:
>> overriding method when in class Http of type [T](chk: (Int) =>
>> Boolean)(hand: dispatch.Handler[T])T;
>> [error] method when in trait RiakkaExceptionHandler of type
>> [T](check: (Int) => Boolean)(handler: dispatch.Handler[T])T cannot
>> override a concrete member without a third member that's overridden by
>> both (this rule is designed to prevent ``accidental overrides'')
>> [error] private def http = new Http with RiakkaExceptionHandler
>> [error] ^
>> [error] one error found
>>
>> I seriously cannot decode that message "cannot override a concrete
>> member without a third member that's overridden by both". What should
>> I do to make the compiler happy?
>>
>> Thanks,
>>
>> Francisco
>>
>
Thu, 2009-12-17, 10:57
#4
Re: Re: [2.8] cannot override a concrete member without a thir
This is actually on my list of things to fix, after we added code to allow overriding a method in a self-type.
Donna
On Thu, Dec 17, 2009 at 10:44 AM, Johannes Rudolph <johannes.rudolph@googlemail.com> wrote:
Donna
On Thu, Dec 17, 2009 at 10:44 AM, Johannes Rudolph <johannes.rudolph@googlemail.com> wrote:
See #2497 (https://lampsvn.epfl.ch/trac/scala/ticket/2497) that's
where the error message was introduced. As I understand it, it should
prevent accidental overriding by mixing in traits.
But in your case something seems odd with the rules. You can even
leave WhenAware completely aside and get the same error. Here, I tried
an even simplier case:
class X {
def test(i:Int):String = i.toString
}
trait ConstantTestImpl { self:X =>
override def test(i:Int):String = "test"
}
(new X with ConstantTestImpl)
<console>:7: error: overriding method test in class X of type (i: Int)String;
method test in trait ConstantTestImpl of type (i: Int)String cannot
override a concrete member without a third member that's overridden by
both (this rule is designed to prevent ``accidental overrides'')
(new X with ConstantTestImpl)
^
This case is different from the one in #2497 in that it actually
defines the self-type and has the override modifier to flag what it
should do. This seems like a very common use case for traits and
should flag errors and many other projects.
For now, the best workaround would be to use:
private[riakka] trait RiakkaExceptionHandler extends Http /*with WhenAware */ {
Johannes
On Thu, Dec 17, 2009 at 10:07 AM, francisco treacy
<francisco.treacy@gmail.com> wrote:
> Hi, could anybody please give me a hint? :) or maybe point me to a
> migration guide if such thing exists?
>
>> cannot override a concrete member without a third member that's overridden by both
>
> concrete member = new Http
> third member = some trait that both RiakkaExceptionHandler and Http mix in (?)
>
> But in that case, it wouldn't be feasible. I don't have access to tell
> Http what it should mix in.
>
>> this rule is designed to prevent ``accidental overrides''
>
> Btw, couldn't it have been a warning instead of an error?
>
> Thanks!
>
> Francisco
>
>
>
>
> 2009/12/15 francisco treacy <francisco.treacy@gmail.com>:
>> Part of my code that compiles fine against 2.7.7 fails to do so
>> against 2.8 beta rc1.
>>
>> I am using Nathan's dispatch library, and I have built a way to
>> override status errors/exceptions. Specifically:
>>
>> import dispatch._
>>
>> private[riakka] trait WhenAware {
>> def when[T](check: Int => Boolean)(handler: Handler[T]): T
>> }
>>
>> /* This behaviour gives us fine-grained control on dealing with
>> low-level exceptions */
>> private[riakka] trait RiakkaExceptionHandler extends WhenAware {
>> abstract override def when[T](check: Int => Boolean)(handler:
>> Handler[T]): T = {
>> try {
>> super.when(check)(handler)
>> } catch {
>> case StatusCode(304, _) => throw NotModified
>> case StatusCode(404, _) => throw new NoSuchElementException
>> }
>> }
>> }
>>
>> abstract class RiakkaException extends RuntimeException
>> object NotModified extends RiakkaException
>>
>> and in my client code I initialize Http mixing in this trait:
>>
>> private def http = new Http with RiakkaExceptionHandler
>>
>> I get:
>>
>> [info] Compiling main sources...
>> [error] /Users/ftreacy/Documents/work/projects/riakka/src/main/scala/Riakka.scala:20:
>> overriding method when in class Http of type [T](chk: (Int) =>
>> Boolean)(hand: dispatch.Handler[T])T;
>> [error] method when in trait RiakkaExceptionHandler of type
>> [T](check: (Int) => Boolean)(handler: dispatch.Handler[T])T cannot
>> override a concrete member without a third member that's overridden by
>> both (this rule is designed to prevent ``accidental overrides'')
>> [error] private def http = new Http with RiakkaExceptionHandler
>> [error] ^
>> [error] one error found
>>
>> I seriously cannot decode that message "cannot override a concrete
>> member without a third member that's overridden by both". What should
>> I do to make the compiler happy?
>>
>> Thanks,
>>
>> Francisco
>>
>
--
Johannes
-----------------------------------------------
Johannes Rudolph
http://virtual-void.net
Thu, 2009-12-17, 11:27
#5
Re: Re: [2.8] cannot override a concrete member without a thir
Yup, that seems to work.
The error message is quite confusing though.
Thanks all!
Francisco
2009/12/17 Johannes Rudolph :
> See #2497 (https://lampsvn.epfl.ch/trac/scala/ticket/2497) that's
> where the error message was introduced. As I understand it, it should
> prevent accidental overriding by mixing in traits.
>
> But in your case something seems odd with the rules. You can even
> leave WhenAware completely aside and get the same error. Here, I tried
> an even simplier case:
>
> class X {
> def test(i:Int):String = i.toString
> }
>
> trait ConstantTestImpl { self:X =>
> override def test(i:Int):String = "test"
> }
>
> (new X with ConstantTestImpl)
>
> :7: error: overriding method test in class X of type (i: Int)String;
> method test in trait ConstantTestImpl of type (i: Int)String cannot
> override a concrete member without a third member that's overridden by
> both (this rule is designed to prevent ``accidental overrides'')
> (new X with ConstantTestImpl)
> ^
>
> This case is different from the one in #2497 in that it actually
> defines the self-type and has the override modifier to flag what it
> should do. This seems like a very common use case for traits and
> should flag errors and many other projects.
>
> For now, the best workaround would be to use:
>
> private[riakka] trait RiakkaExceptionHandler extends Http /*with WhenAware */ {
>
> Johannes
>
> On Thu, Dec 17, 2009 at 10:07 AM, francisco treacy
> wrote:
>> Hi, could anybody please give me a hint? :) or maybe point me to a
>> migration guide if such thing exists?
>>
>>> cannot override a concrete member without a third member that's overridden by both
>>
>> concrete member = new Http
>> third member = some trait that both RiakkaExceptionHandler and Http mix in (?)
>>
>> But in that case, it wouldn't be feasible. I don't have access to tell
>> Http what it should mix in.
>>
>>> this rule is designed to prevent ``accidental overrides''
>>
>> Btw, couldn't it have been a warning instead of an error?
>>
>> Thanks!
>>
>> Francisco
>>
>>
>>
>>
>> 2009/12/15 francisco treacy :
>>> Part of my code that compiles fine against 2.7.7 fails to do so
>>> against 2.8 beta rc1.
>>>
>>> I am using Nathan's dispatch library, and I have built a way to
>>> override status errors/exceptions. Specifically:
>>>
>>> import dispatch._
>>>
>>> private[riakka] trait WhenAware {
>>> def when[T](check: Int => Boolean)(handler: Handler[T]): T
>>> }
>>>
>>> /* This behaviour gives us fine-grained control on dealing with
>>> low-level exceptions */
>>> private[riakka] trait RiakkaExceptionHandler extends WhenAware {
>>> abstract override def when[T](check: Int => Boolean)(handler:
>>> Handler[T]): T = {
>>> try {
>>> super.when(check)(handler)
>>> } catch {
>>> case StatusCode(304, _) => throw NotModified
>>> case StatusCode(404, _) => throw new NoSuchElementException
>>> }
>>> }
>>> }
>>>
>>> abstract class RiakkaException extends RuntimeException
>>> object NotModified extends RiakkaException
>>>
>>> and in my client code I initialize Http mixing in this trait:
>>>
>>> private def http = new Http with RiakkaExceptionHandler
>>>
>>> I get:
>>>
>>> [info] Compiling main sources...
>>> [error] /Users/ftreacy/Documents/work/projects/riakka/src/main/scala/Riakka.scala:20:
>>> overriding method when in class Http of type [T](chk: (Int) =>
>>> Boolean)(hand: dispatch.Handler[T])T;
>>> [error] method when in trait RiakkaExceptionHandler of type
>>> [T](check: (Int) => Boolean)(handler: dispatch.Handler[T])T cannot
>>> override a concrete member without a third member that's overridden by
>>> both (this rule is designed to prevent ``accidental overrides'')
>>> [error] private def http = new Http with RiakkaExceptionHandler
>>> [error] ^
>>> [error] one error found
>>>
>>> I seriously cannot decode that message "cannot override a concrete
>>> member without a third member that's overridden by both". What should
>>> I do to make the compiler happy?
>>>
>>> Thanks,
>>>
>>> Francisco
>>>
>>
>
>
>
> --
> Johannes
>
> -----------------------------------------------
> Johannes Rudolph
> http://virtual-void.net
>
Thu, 2009-12-17, 11:37
#6
Re: Re: [2.8] cannot override a concrete member without a thir
On Thu, Dec 17, 2009 at 10:54 AM, Donna Malayeri wrote:
> This is actually on my list of things to fix, after we added code to allow
> overriding a method in a self-type.
Ah, that's nice. Is there already a ticket for us to subscribe to?
I was under the impression that it would be possible to override
methods in self-types right now. Can anyone give some explanation or
examples what the practical differences for traits are between
extending a class or declaring it as a self-type?
Johannes
>
> Donna
>
> On Thu, Dec 17, 2009 at 10:44 AM, Johannes Rudolph
> wrote:
>>
>> See #2497 (https://lampsvn.epfl.ch/trac/scala/ticket/2497) that's
>> where the error message was introduced. As I understand it, it should
>> prevent accidental overriding by mixing in traits.
>>
>> But in your case something seems odd with the rules. You can even
>> leave WhenAware completely aside and get the same error. Here, I tried
>> an even simplier case:
>>
>> class X {
>> def test(i:Int):String = i.toString
>> }
>>
>> trait ConstantTestImpl { self:X =>
>> override def test(i:Int):String = "test"
>> }
>>
>> (new X with ConstantTestImpl)
>>
>> :7: error: overriding method test in class X of type (i:
>> Int)String;
>> method test in trait ConstantTestImpl of type (i: Int)String cannot
>> override a concrete member without a third member that's overridden by
>> both (this rule is designed to prevent ``accidental overrides'')
>> (new X with ConstantTestImpl)
>> ^
>>
>> This case is different from the one in #2497 in that it actually
>> defines the self-type and has the override modifier to flag what it
>> should do. This seems like a very common use case for traits and
>> should flag errors and many other projects.
>>
>> For now, the best workaround would be to use:
>>
>> private[riakka] trait RiakkaExceptionHandler extends Http /*with WhenAware
>> */ {
>>
>> Johannes
>>
>> On Thu, Dec 17, 2009 at 10:07 AM, francisco treacy
>> wrote:
>> > Hi, could anybody please give me a hint? :) or maybe point me to a
>> > migration guide if such thing exists?
>> >
>> >> cannot override a concrete member without a third member that's
>> >> overridden by both
>> >
>> > concrete member = new Http
>> > third member = some trait that both RiakkaExceptionHandler and Http mix
>> > in (?)
>> >
>> > But in that case, it wouldn't be feasible. I don't have access to tell
>> > Http what it should mix in.
>> >
>> >> this rule is designed to prevent ``accidental overrides''
>> >
>> > Btw, couldn't it have been a warning instead of an error?
>> >
>> > Thanks!
>> >
>> > Francisco
>> >
>> >
>> >
>> >
>> > 2009/12/15 francisco treacy :
>> >> Part of my code that compiles fine against 2.7.7 fails to do so
>> >> against 2.8 beta rc1.
>> >>
>> >> I am using Nathan's dispatch library, and I have built a way to
>> >> override status errors/exceptions. Specifically:
>> >>
>> >> import dispatch._
>> >>
>> >> private[riakka] trait WhenAware {
>> >> def when[T](check: Int => Boolean)(handler: Handler[T]): T
>> >> }
>> >>
>> >> /* This behaviour gives us fine-grained control on dealing with
>> >> low-level exceptions */
>> >> private[riakka] trait RiakkaExceptionHandler extends WhenAware {
>> >> abstract override def when[T](check: Int => Boolean)(handler:
>> >> Handler[T]): T = {
>> >> try {
>> >> super.when(check)(handler)
>> >> } catch {
>> >> case StatusCode(304, _) => throw NotModified
>> >> case StatusCode(404, _) => throw new NoSuchElementException
>> >> }
>> >> }
>> >> }
>> >>
>> >> abstract class RiakkaException extends RuntimeException
>> >> object NotModified extends RiakkaException
>> >>
>> >> and in my client code I initialize Http mixing in this trait:
>> >>
>> >> private def http = new Http with RiakkaExceptionHandler
>> >>
>> >> I get:
>> >>
>> >> [info] Compiling main sources...
>> >> [error]
>> >> /Users/ftreacy/Documents/work/projects/riakka/src/main/scala/Riakka.scala:20:
>> >> overriding method when in class Http of type [T](chk: (Int) =>
>> >> Boolean)(hand: dispatch.Handler[T])T;
>> >> [error] method when in trait RiakkaExceptionHandler of type
>> >> [T](check: (Int) => Boolean)(handler: dispatch.Handler[T])T cannot
>> >> override a concrete member without a third member that's overridden by
>> >> both (this rule is designed to prevent ``accidental overrides'')
>> >> [error] private def http = new Http with RiakkaExceptionHandler
>> >> [error] ^
>> >> [error] one error found
>> >>
>> >> I seriously cannot decode that message "cannot override a concrete
>> >> member without a third member that's overridden by both". What should
>> >> I do to make the compiler happy?
>> >>
>> >> Thanks,
>> >>
>> >> Francisco
>> >>
>> >
>>
>>
>>
>> --
>> Johannes
>>
>> -----------------------------------------------
>> Johannes Rudolph
>> http://virtual-void.net
>
>
Thu, 2009-12-17, 11:47
#7
Re: Re: [2.8] cannot override a concrete member without a thir
Declaring it as a self-type is more flexible, because it sets up a looser coupling between the classes. Also, it turns out that if you use self-types instead of inheritance, you can avoid inheritance diamonds (see my paper "CZ: Multiple Inheritance Without Diamonds" at www.cs.cmu.edu/~donna/public/oopsla09.pdf). We are also considering adding a feature for allowing traits to take constructor parameters if they are not the root of an inheritance diamond (which can be avoided if self-types are used). This is still in the early design stages, however.
Donna
On Thu, Dec 17, 2009 at 11:21 AM, Johannes Rudolph <johannes.rudolph@googlemail.com> wrote:
Donna
On Thu, Dec 17, 2009 at 11:21 AM, Johannes Rudolph <johannes.rudolph@googlemail.com> wrote:
On Thu, Dec 17, 2009 at 10:54 AM, Donna Malayeri <lindydonna@gmail.com> wrote:
> This is actually on my list of things to fix, after we added code to allow
> overriding a method in a self-type.
Ah, that's nice. Is there already a ticket for us to subscribe to?
I was under the impression that it would be possible to override
methods in self-types right now. Can anyone give some explanation or
examples what the practical differences for traits are between
extending a class or declaring it as a self-type?
Johannes
>
> Donna
>
> On Thu, Dec 17, 2009 at 10:44 AM, Johannes Rudolph
> <johannes.rudolph@googlemail.com> wrote:
>>
>> See #2497 (https://lampsvn.epfl.ch/trac/scala/ticket/2497) that's
>> where the error message was introduced. As I understand it, it should
>> prevent accidental overriding by mixing in traits.
>>
>> But in your case something seems odd with the rules. You can even
>> leave WhenAware completely aside and get the same error. Here, I tried
>> an even simplier case:
>>
>> class X {
>> def test(i:Int):String = i.toString
>> }
>>
>> trait ConstantTestImpl { self:X =>
>> override def test(i:Int):String = "test"
>> }
>>
>> (new X with ConstantTestImpl)
>>
>> <console>:7: error: overriding method test in class X of type (i:
>> Int)String;
>> method test in trait ConstantTestImpl of type (i: Int)String cannot
>> override a concrete member without a third member that's overridden by
>> both (this rule is designed to prevent ``accidental overrides'')
>> (new X with ConstantTestImpl)
>> ^
>>
>> This case is different from the one in #2497 in that it actually
>> defines the self-type and has the override modifier to flag what it
>> should do. This seems like a very common use case for traits and
>> should flag errors and many other projects.
>>
>> For now, the best workaround would be to use:
>>
>> private[riakka] trait RiakkaExceptionHandler extends Http /*with WhenAware
>> */ {
>>
>> Johannes
>>
>> On Thu, Dec 17, 2009 at 10:07 AM, francisco treacy
>> <francisco.treacy@gmail.com> wrote:
>> > Hi, could anybody please give me a hint? :) or maybe point me to a
>> > migration guide if such thing exists?
>> >
>> >> cannot override a concrete member without a third member that's
>> >> overridden by both
>> >
>> > concrete member = new Http
>> > third member = some trait that both RiakkaExceptionHandler and Http mix
>> > in (?)
>> >
>> > But in that case, it wouldn't be feasible. I don't have access to tell
>> > Http what it should mix in.
>> >
>> >> this rule is designed to prevent ``accidental overrides''
>> >
>> > Btw, couldn't it have been a warning instead of an error?
>> >
>> > Thanks!
>> >
>> > Francisco
>> >
>> >
>> >
>> >
>> > 2009/12/15 francisco treacy <francisco.treacy@gmail.com>:
>> >> Part of my code that compiles fine against 2.7.7 fails to do so
>> >> against 2.8 beta rc1.
>> >>
>> >> I am using Nathan's dispatch library, and I have built a way to
>> >> override status errors/exceptions. Specifically:
>> >>
>> >> import dispatch._
>> >>
>> >> private[riakka] trait WhenAware {
>> >> def when[T](check: Int => Boolean)(handler: Handler[T]): T
>> >> }
>> >>
>> >> /* This behaviour gives us fine-grained control on dealing with
>> >> low-level exceptions */
>> >> private[riakka] trait RiakkaExceptionHandler extends WhenAware {
>> >> abstract override def when[T](check: Int => Boolean)(handler:
>> >> Handler[T]): T = {
>> >> try {
>> >> super.when(check)(handler)
>> >> } catch {
>> >> case StatusCode(304, _) => throw NotModified
>> >> case StatusCode(404, _) => throw new NoSuchElementException
>> >> }
>> >> }
>> >> }
>> >>
>> >> abstract class RiakkaException extends RuntimeException
>> >> object NotModified extends RiakkaException
>> >>
>> >> and in my client code I initialize Http mixing in this trait:
>> >>
>> >> private def http = new Http with RiakkaExceptionHandler
>> >>
>> >> I get:
>> >>
>> >> [info] Compiling main sources...
>> >> [error]
>> >> /Users/ftreacy/Documents/work/projects/riakka/src/main/scala/Riakka.scala:20:
>> >> overriding method when in class Http of type [T](chk: (Int) =>
>> >> Boolean)(hand: dispatch.Handler[T])T;
>> >> [error] method when in trait RiakkaExceptionHandler of type
>> >> [T](check: (Int) => Boolean)(handler: dispatch.Handler[T])T cannot
>> >> override a concrete member without a third member that's overridden by
>> >> both (this rule is designed to prevent ``accidental overrides'')
>> >> [error] private def http = new Http with RiakkaExceptionHandler
>> >> [error] ^
>> >> [error] one error found
>> >>
>> >> I seriously cannot decode that message "cannot override a concrete
>> >> member without a third member that's overridden by both". What should
>> >> I do to make the compiler happy?
>> >>
>> >> Thanks,
>> >>
>> >> Francisco
>> >>
>> >
>>
>>
>>
>> --
>> Johannes
>>
>> -----------------------------------------------
>> Johannes Rudolph
>> http://virtual-void.net
>
>
--
Johannes
-----------------------------------------------
Johannes Rudolph
http://virtual-void.net
Thu, 2009-12-17, 11:57
#8
Re: Re: [2.8] cannot override a concrete member without a thir
To answer your other question, I just created a ticket for this: https://lampsvn.epfl.ch/trac/scala/ticket/2808
Donna
On Thu, Dec 17, 2009 at 11:21 AM, Johannes Rudolph <johannes.rudolph@googlemail.com> wrote:
Donna
On Thu, Dec 17, 2009 at 11:21 AM, Johannes Rudolph <johannes.rudolph@googlemail.com> wrote:
On Thu, Dec 17, 2009 at 10:54 AM, Donna Malayeri <lindydonna@gmail.com> wrote:
> This is actually on my list of things to fix, after we added code to allow
> overriding a method in a self-type.
Ah, that's nice. Is there already a ticket for us to subscribe to?
I was under the impression that it would be possible to override
methods in self-types right now. Can anyone give some explanation or
examples what the practical differences for traits are between
extending a class or declaring it as a self-type?
Johannes
>
> Donna
>
> On Thu, Dec 17, 2009 at 10:44 AM, Johannes Rudolph
> <johannes.rudolph@googlemail.com> wrote:
>>
>> See #2497 (https://lampsvn.epfl.ch/trac/scala/ticket/2497) that's
>> where the error message was introduced. As I understand it, it should
>> prevent accidental overriding by mixing in traits.
>>
>> But in your case something seems odd with the rules. You can even
>> leave WhenAware completely aside and get the same error. Here, I tried
>> an even simplier case:
>>
>> class X {
>> def test(i:Int):String = i.toString
>> }
>>
>> trait ConstantTestImpl { self:X =>
>> override def test(i:Int):String = "test"
>> }
>>
>> (new X with ConstantTestImpl)
>>
>> <console>:7: error: overriding method test in class X of type (i:
>> Int)String;
>> method test in trait ConstantTestImpl of type (i: Int)String cannot
>> override a concrete member without a third member that's overridden by
>> both (this rule is designed to prevent ``accidental overrides'')
>> (new X with ConstantTestImpl)
>> ^
>>
>> This case is different from the one in #2497 in that it actually
>> defines the self-type and has the override modifier to flag what it
>> should do. This seems like a very common use case for traits and
>> should flag errors and many other projects.
>>
>> For now, the best workaround would be to use:
>>
>> private[riakka] trait RiakkaExceptionHandler extends Http /*with WhenAware
>> */ {
>>
>> Johannes
>>
>> On Thu, Dec 17, 2009 at 10:07 AM, francisco treacy
>> <francisco.treacy@gmail.com> wrote:
>> > Hi, could anybody please give me a hint? :) or maybe point me to a
>> > migration guide if such thing exists?
>> >
>> >> cannot override a concrete member without a third member that's
>> >> overridden by both
>> >
>> > concrete member = new Http
>> > third member = some trait that both RiakkaExceptionHandler and Http mix
>> > in (?)
>> >
>> > But in that case, it wouldn't be feasible. I don't have access to tell
>> > Http what it should mix in.
>> >
>> >> this rule is designed to prevent ``accidental overrides''
>> >
>> > Btw, couldn't it have been a warning instead of an error?
>> >
>> > Thanks!
>> >
>> > Francisco
>> >
>> >
>> >
>> >
>> > 2009/12/15 francisco treacy <francisco.treacy@gmail.com>:
>> >> Part of my code that compiles fine against 2.7.7 fails to do so
>> >> against 2.8 beta rc1.
>> >>
>> >> I am using Nathan's dispatch library, and I have built a way to
>> >> override status errors/exceptions. Specifically:
>> >>
>> >> import dispatch._
>> >>
>> >> private[riakka] trait WhenAware {
>> >> def when[T](check: Int => Boolean)(handler: Handler[T]): T
>> >> }
>> >>
>> >> /* This behaviour gives us fine-grained control on dealing with
>> >> low-level exceptions */
>> >> private[riakka] trait RiakkaExceptionHandler extends WhenAware {
>> >> abstract override def when[T](check: Int => Boolean)(handler:
>> >> Handler[T]): T = {
>> >> try {
>> >> super.when(check)(handler)
>> >> } catch {
>> >> case StatusCode(304, _) => throw NotModified
>> >> case StatusCode(404, _) => throw new NoSuchElementException
>> >> }
>> >> }
>> >> }
>> >>
>> >> abstract class RiakkaException extends RuntimeException
>> >> object NotModified extends RiakkaException
>> >>
>> >> and in my client code I initialize Http mixing in this trait:
>> >>
>> >> private def http = new Http with RiakkaExceptionHandler
>> >>
>> >> I get:
>> >>
>> >> [info] Compiling main sources...
>> >> [error]
>> >> /Users/ftreacy/Documents/work/projects/riakka/src/main/scala/Riakka.scala:20:
>> >> overriding method when in class Http of type [T](chk: (Int) =>
>> >> Boolean)(hand: dispatch.Handler[T])T;
>> >> [error] method when in trait RiakkaExceptionHandler of type
>> >> [T](check: (Int) => Boolean)(handler: dispatch.Handler[T])T cannot
>> >> override a concrete member without a third member that's overridden by
>> >> both (this rule is designed to prevent ``accidental overrides'')
>> >> [error] private def http = new Http with RiakkaExceptionHandler
>> >> [error] ^
>> >> [error] one error found
>> >>
>> >> I seriously cannot decode that message "cannot override a concrete
>> >> member without a third member that's overridden by both". What should
>> >> I do to make the compiler happy?
>> >>
>> >> Thanks,
>> >>
>> >> Francisco
>> >>
>> >
>>
>>
>>
>> --
>> Johannes
>>
>> -----------------------------------------------
>> Johannes Rudolph
>> http://virtual-void.net
>
>
--
Johannes
-----------------------------------------------
Johannes Rudolph
http://virtual-void.net
Hi, could anybody please give me a hint? :) or maybe point me to a
migration guide if such thing exists?
> cannot override a concrete member without a third member that's overridden by both
concrete member = new Http
third member = some trait that both RiakkaExceptionHandler and Http mix in (?)
But in that case, it wouldn't be feasible. I don't have access to tell
Http what it should mix in.
> this rule is designed to prevent ``accidental overrides''
Btw, couldn't it have been a warning instead of an error?
Thanks!
Francisco
2009/12/15 francisco treacy :
> Part of my code that compiles fine against 2.7.7 fails to do so
> against 2.8 beta rc1.
>
> I am using Nathan's dispatch library, and I have built a way to
> override status errors/exceptions. Specifically:
>
> import dispatch._
>
> private[riakka] trait WhenAware {
> def when[T](check: Int => Boolean)(handler: Handler[T]): T
> }
>
> /* This behaviour gives us fine-grained control on dealing with
> low-level exceptions */
> private[riakka] trait RiakkaExceptionHandler extends WhenAware {
> abstract override def when[T](check: Int => Boolean)(handler:
> Handler[T]): T = {
> try {
> super.when(check)(handler)
> } catch {
> case StatusCode(304, _) => throw NotModified
> case StatusCode(404, _) => throw new NoSuchElementException
> }
> }
> }
>
> abstract class RiakkaException extends RuntimeException
> object NotModified extends RiakkaException
>
> and in my client code I initialize Http mixing in this trait:
>
> private def http = new Http with RiakkaExceptionHandler
>
> I get:
>
> [info] Compiling main sources...
> [error] /Users/ftreacy/Documents/work/projects/riakka/src/main/scala/Riakka.scala:20:
> overriding method when in class Http of type [T](chk: (Int) =>
> Boolean)(hand: dispatch.Handler[T])T;
> [error] method when in trait RiakkaExceptionHandler of type
> [T](check: (Int) => Boolean)(handler: dispatch.Handler[T])T cannot
> override a concrete member without a third member that's overridden by
> both (this rule is designed to prevent ``accidental overrides'')
> [error] private def http = new Http with RiakkaExceptionHandler
> [error] ^
> [error] one error found
>
> I seriously cannot decode that message "cannot override a concrete
> member without a third member that's overridden by both". What should
> I do to make the compiler happy?
>
> Thanks,
>
> Francisco
>