OOlib icon indicating copy to clipboard operation
OOlib copied to clipboard

`pick` does not work with `isInstanceOf`, when should (protocol == protocol)

Open griffith1deady opened this issue 1 year ago • 1 comments

import oolib

protocol Session:
    proc connect()
    proc disconnect() 

protocol Streamable:
    proc read(): string
    proc write(data: string)

class Player impl (Session, Streamable):
    proc connect() = echo "Player connected"
    proc disconnect() = echo "Player disconnected"
    proc read(): string = echo "Reading"
    proc write(data: string) = echo "Writing"

proc resolve(self: Session) = echo self

let player = Player.new()
let playerProtocol = player.toProtocol()
resolve(playerProtocol.pick(Session))

let session = playerProtocol.pick(Session)
echo session.isInstanceOf(Session) ## false
echo session.isInstanceOf(Streamable) ## false
echo session.isInstanceOf(Player) ## false

griffith1deady avatar Jul 04 '24 18:07 griffith1deady

To be honest I haven't decided how to implement isInstanceOf on protocol itself yet, because It's obvious that an instance of a certain protocol like session has the structure of Session type(though the same can be said for the relation between player and Player) and I don't know if there's a case where an instance of protocol need type-checking.

glassesneo avatar Jul 05 '24 01:07 glassesneo