Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix regression with imported distinct types #1418

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions compiler/mir/mirtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1085,11 +1085,13 @@ proc handleImported(env: var TypeEnv, t: PType): TypeId =
if t.sym != nil and sfImportc in t.sym.flags:
# an imported type. It's wrapped in a ``tkImported``, referencing the
# underlying type
let base = typeSymToMir(env):
let base =
if t.kind in Skip:
t.lastSon.skipIrrelevant()
env.add t.lastSon.skipIrrelevant()
else:
t
# create a type symbol without going through the cache or ``.importc``
# handling
typeSymToMir(env, t)

discard getSize(env.config, t) # compute the sizes, alignments, and offsets

Expand Down
15 changes: 15 additions & 0 deletions tests/ccgbugs/timport_distinct.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
discard """
description: '''
Regression test for importing ``distinct`` types resulting in duplicate C
type definitions
'''
"""

type
Object = object
Imported {.importc: "int", nodecl.} = distinct Object

var x: Object
var y: Imported

# two type definitions for `Object` were emitted
Loading