summary refs log tree commit diff stats
path: root/compiler/semstmts.nim
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2017-05-13 15:46:08 +0300
committerZahary Karadjov <zahary@gmail.com>2017-05-13 15:46:08 +0300
commitb428da2cc2e7785ed9cb9a7efa1d2fa219603b59 (patch)
tree387b5831e79af165081a75f9d43f007832cd1fc1 /compiler/semstmts.nim
parent0aede22e87926304ca1eea0e96805e4e58fb5d7b (diff)
downloadNim-b428da2cc2e7785ed9cb9a7efa1d2fa219603b59.tar.gz
work-around for defining imported types with weak covariance
Diffstat (limited to 'compiler/semstmts.nim')
-rw-r--r--compiler/semstmts.nim16
1 files changed, 16 insertions, 0 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 4c1fbede3..10fc6fb6d 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -867,6 +867,22 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
         s.typ.sons[sonsLen(s.typ) - 1] = body
         if sfCovariant in s.flags:
           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)
       closeScope(c)