work-around for defining imported types with weak covariance
This commit is contained in:
parent
0aede22e87
commit
b428da2cc2
2 changed files with 23 additions and 4 deletions
|
|
@ -867,6 +867,22 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||||
s.typ.sons[sonsLen(s.typ) - 1] = body
|
s.typ.sons[sonsLen(s.typ) - 1] = body
|
||||||
if sfCovariant in s.flags:
|
if sfCovariant in s.flags:
|
||||||
checkCovariantParamsUsages(s.typ)
|
checkCovariantParamsUsages(s.typ)
|
||||||
|
# XXX: This is a temporary limitation:
|
||||||
|
# The codegen currently produces various failures with
|
||||||
|
# generic imported types that have fields, but we need
|
||||||
|
# the fields specified in order to detect weak covariance.
|
||||||
|
# The proper solution is to teach the codegen how to handle
|
||||||
|
# such types, because this would offer various interesting
|
||||||
|
# possibilities such as instantiating C++ generic types with
|
||||||
|
# garbage collected Nim types.
|
||||||
|
if sfImportc in s.flags:
|
||||||
|
var body = s.typ.lastSon
|
||||||
|
if body.kind == tyObject:
|
||||||
|
# erases all declared fields
|
||||||
|
body.n.sons = nil
|
||||||
|
|
||||||
|
debug s.typ
|
||||||
|
echo s.typ[0].sym.flags
|
||||||
|
|
||||||
popOwner(c)
|
popOwner(c)
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ template acceptWithCovariance(x, otherwise): typed =
|
||||||
skipElse(otherwise)
|
skipElse(otherwise)
|
||||||
|
|
||||||
type
|
type
|
||||||
Animal = object of TObject
|
Animal = object of RootObj
|
||||||
x: string
|
x: string
|
||||||
|
|
||||||
Dog = object of Animal
|
Dog = object of Animal
|
||||||
|
|
@ -302,12 +302,15 @@ reject wantsVarPointer2(pcat)
|
||||||
|
|
||||||
{.emit: """
|
{.emit: """
|
||||||
template <class T> struct FN { typedef void (*type)(T); };
|
template <class T> struct FN { typedef void (*type)(T); };
|
||||||
template <class T> struct ARR { typedef T type[2]; };
|
template <class T> struct ARR { typedef T DataType[2]; DataType data; };
|
||||||
""".}
|
""".}
|
||||||
|
|
||||||
type
|
type
|
||||||
MyPtr {.importcpp: "'0 *"} [out T] = distinct ptr T
|
MyPtr {.importcpp: "'0 *"} [out T] = object
|
||||||
MySeq {.importcpp: "ARR<'0>::type"} [out T] = object
|
|
||||||
|
MySeq {.importcpp: "ARR<'0>", nodecl} [out T] = object
|
||||||
|
data: array[2, T]
|
||||||
|
|
||||||
MyAction {.importcpp: "FN<'0>::type"} [in T] = object
|
MyAction {.importcpp: "FN<'0>::type"} [in T] = object
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue