glassesneo / OOlib

A nimble package for object-oriented programming
Do What The F*ck You Want To Public License
64 stars 4 forks source link

Generic bug in `protocol` #141

Closed griffith1deady closed 3 days ago

griffith1deady commented 3 days ago
import oolib

protocol ProcessManager:
    proc setup(processId: int64)
    proc getBaseAddress(): int64
    #proc read[T](address: int64, size: int64): T # Compile error, undeclared identifier: 'T'
    #proc write[T](address: int64, value: T) # Compile error, undeclared identifier: 'T'
    proc destroy()

type ProcessManagerImpl = object

proc setup(self: ProcessManagerImpl, processId: int64) =
  echo "Setting up process manager for process ", processId

proc getBaseAddress(self: ProcessManagerImpl): int64 =
  echo "Getting base address"
  return 0

proc read[T](self: ProcessManagerImpl, address: int64, size: int64): T = # Compiled successfully
  echo "Reading ", size, " bytes from address ", address
  return cast[T](address)

proc write[T](self: ProcessManagerImpl, address: int64, value: T) = # Compiled successfully
  echo "Writing ", value, " to address ", address

proc destroy(self: ProcessManagerImpl) =
  echo "Destroying process manager"
griffith1deady commented 3 days ago

And trying to declare in protocol like procedures with default implementation (maybe like as a workaround), but i see like that #94 feature doesn't really implemented, but issue status is Completed

Error: Protocol cannot have procedure implementation
glassesneo commented 3 days ago

The feature was once implemented, however it has been removed in 0.7.0 due to its complexity. The issue about its re-implementation is here but I'm considering it carefully for the same reason.