Skip to content

Concepts with inheritance causing 'SIGSEGV: Illegal storage access ...' #10506

Open
@deech

Description

@deech

Concepts don't seem to handle subtypes very well, the following code:

type
   Foo = object of RootObj
   Bar = object of Foo

   FooOrBar = concept s, type T
     s is T
     f(s) is string

proc f(f: Foo): string = "Foo"

proc conceptf(f : FooOrBar): string =
  f(f)

let bar = Bar()
echo conceptf(bar)

generates the following error:

Hint: system [Processing]
Hint: concepttest [Processing]
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

While Nim should not SIGSEGV when compiling this snippet I think concepts should not try and follow inheritance hierarchies and the line s is T should mean s is exactly T and not s is T or a subtype of T. Coming from Scala my experience is subtype + typeclasses (or concepts) causes horrendous type inference and makes concept resolution very hard to reason about.

TLDR: This compiler should not SIGSEGV on this code but it shouldn't typecheck either because concepts + subtyping leads to bad or hard to understand behavior.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions