-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prepending a module into a class results in Unexpected Super
#332
Comments
found my answer:
|
actually then all type checking stops. hmm. |
@jubishop Could you give me the RBS files? Seems like you need to add module-self-type constraint in the module declaration: interface _DateTimeMinus
def -: (untyped) -> DateTime
end
module DateTimeDurationExtensions : _DateTimeMinus # The module have to be mixed to classes compatible to _DateTimeMinus
def -: (untyped) -> DateTime
end |
thanks @soutaro for looking into this! I've attached the 3 files to show a simple example of my problem. |
actually your interface hint worked for me. :) I don't fully understand why tho, and wish I did :) why does having the module adhere to the interface allow super() calls, whereas just defining it in the module itself doesn't? |
Here's a more interesting example with the However if I remove the second definition for |
In the second example, the error around Unfortunately, type checking I assume that you want to extend interface _DateTimeAdd
def +: (DateTime) -> DateTime
end
module DateTimeDurationExtensions : _DateTimeAdd
include _DateTimeAdd
def +: (String) -> DateTime
| ...
end
class DateTime
include DateTimeDurationExtensions
end |
I can't put any combination together that works for me. I'm trying to reuse the
And any |
If I try to |
How about this? class Duration
end
interface _TimeDurationExtensions
def +: (Numeric other) -> Time
end
module TimeDurationExtensions : _TimeDurationExtensions
def +: (Duration other) -> Time
| ...
end
class Time
prepend TimeDurationExtensions
end module TimeDurationExtensions
def +(other)
case other
when Duration
Time.new
else
super(other)
end
end
end
class Time
prepend TimeDurationExtensions
end
Time.new + Duration.new
Time.new + 3 |
ohh I didn't understand class Duration
end
interface _TimeDurationExtensions
def -: (Numeric other) -> Time
| (Time other) -> Float
end
module TimeDurationExtensions : _TimeDurationExtensions
def -: (Duration other) -> Time
| ...
end
class Time
prepend TimeDurationExtensions
end require 'time'
module TimeDurationExtensions
def -(other)
case other
when Duration
Time.new
else
super(other)
end
end
end
class Time
prepend TimeDurationExtensions
end
Time.new - Time.new
Time.new - 3
Time.new - Duration.new |
Hmm, the |
Haha well thanks for investigating. I wish I could commit a fix but the code is beyond me 🥲 |
this results in
Unexpected Super
, but there is a-
method inside theDate
class.The text was updated successfully, but these errors were encountered: