Skip to content

Concept proc resolution issue with posix.read #6782

@euantorano

Description

@euantorano

The following code reports false, true when the expected result is true, true:

import os, posix

type
    Reader = concept c
        c.read(openarray[byte], int, int) is int
        
    Rdr = concept c
        c.rd(openarray[byte], int, int) is int
        
type
    TestFile = object
    
proc read(r: TestFile, dest: openarray[byte], offset: int, limit: int): int =
    result = 0
    
proc rd(r: TestFile, dest: openarray[byte], offset: int, limit: int): int =
    result = 0
    
when isMainModule:
    echo TestFile is Reader, ", ", TestFile is Rdr

However, if you exclude posix.read from being imported it works:

import os
import posix except read

type
    Reader = concept c
        c.read(openarray[byte], int, int) is int
        
    Rdr = concept c
        c.rd(openarray[byte], int, int) is int
        
type
    TestFile = object
    
proc read(r: TestFile, dest: openarray[byte], offset: int, limit: int): int =
    result = 0
    
proc rd(r: TestFile, dest: openarray[byte], offset: int, limit: int): int =
    result = 0
    
when isMainModule:
    echo TestFile is Reader, ", ", TestFile is Rdr

Another interesting case is the following:

import os
from posix import nil

type
    Reader = concept c
        c.read(openarray[byte], int, int) is int
        
    Rdr = concept c
        c.rd(openarray[byte], int, int) is int
        
    Closer = concept c
        c.close()
        
type
    TestFile = object
    
proc read(r: TestFile, dest: openarray[byte], offset: int, limit: int): int =
    result = 0
    
proc rd(r: TestFile, dest: openarray[byte], offset: int, limit: int): int =
    result = 0
    
proc close(r: TestFile) =
    discard
    
when isMainModule:
    echo TestFile is Reader, ", ", TestFile is Rdr
    echo TestFile is Closer

I would expect an output of

true, true
true

But instead get

true, true
false

Perhaps this second case is a misunderstanding on my part...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions