Open
Description
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.