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

"incompatible type" when mixing float32 and cfloat in generics #19349

Closed
oakes opened this issue Jan 9, 2022 · 2 comments · Fixed by #20551
Closed

"incompatible type" when mixing float32 and cfloat in generics #19349

oakes opened this issue Jan 9, 2022 · 2 comments · Fixed by #20551

Comments

@oakes
Copy link

oakes commented Jan 9, 2022

Mixing float32 and cfloat can sometimes lead to a strange error that exposes the generated C code.

Example

type
  Vec3[T: SomeNumber] = object
    arr: array[3, T]

var 
  cfloatArr: array[3, array[3, cfloat]]
  cfloatSeq = newSeq[Vec3[cfloat]]()
for row in cfloatArr:
  cfloatSeq.add(Vec3[float32](arr: [row[0], row[1], row[2]]))
echo cfloatSeq

Current Output

/Users/sekao/.cache/nim/nim_misc_d/@mnim_misc.nim.c:449:40: error: assigning to 'tyObject_Vec3__a2hI8d3noWjXtSOVv1UfRA' (aka 'struct tyObject_Vec3__a2hI8d3noWjXtSOVv1UfRA') from
      incompatible type 'tyObject_Vec3__c79bdlxFEYQ7KlCcTS4NeNw' (aka 'struct tyObject_Vec3__c79bdlxFEYQ7KlCcTS4NeNw')
                                cfloatSeq__nim95misc_37->data[T5_] = T4_;

Expected Output

@[(arr: [0.0, 0.0, 0.0]), (arr: [0.0, 0.0, 0.0]), (arr: [0.0, 0.0, 0.0])]

Additional Information

The code works in nim 1.2.6.

$ nim -v
Nim Compiler Version 1.6.2 [MacOSX: amd64]
Compiled at 2021-12-17
Copyright (c) 2006-2021 by Andreas Rumpf
@Vindaar
Copy link
Contributor

Vindaar commented Jan 12, 2022

As this seems to be somewhat related to #19374 I checked whether the fix to #16246, specifically:
e8dad48#diff-23877fff4d200f490b74503f9db6fced353182598a5b72e8925598f2430bd6b0R1148-R1154
caused this regression.

That seems to be the case. Taking out the added code makes the example compile again.

oakes added a commit to paranim/paranim_examples that referenced this issue Feb 16, 2022
@ringabout
Copy link
Member

Works in 1.4.8 not in 1.6.0

bung87 added a commit to bung87/Nim that referenced this issue Oct 12, 2022
bung87 added a commit to bung87/Nim that referenced this issue Oct 13, 2022
bung87 added a commit to bung87/Nim that referenced this issue Oct 14, 2022
bung87 added a commit to bung87/Nim that referenced this issue Oct 14, 2022
narimiran pushed a commit that referenced this issue Oct 24, 2022
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
bung87 added a commit to bung87/Nim that referenced this issue Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants