Open lilkeet opened 1 month ago
!nim c
import std / sequtils
type
OrderedContainer*[T] = concept x # basically openarray in concept form
x.len is SomeInteger
for index, item in x.pairs:
index is Ordinal
item is T
type IndexType = typeOf(x.pairs.toSeq[0].key)
x[IndexType] is T
let exampleData = @[1, 2, 3]
block conceptInsideOpenArray:
proc conceptProc[T](arg: OrderedContainer[T]) =
echo arg.len
proc openarrayProc[T](arg: openarray[T]) =
conceptProc(arg)
conceptProc(exampleData) # compiles
openarrayProc(exampleData) # code gen fails
block openArrayInsideConcept:
proc openarrayProc2[T](arg: openarray[T]) =
echo arg.len
proc conceptProc2[T](arg: OrderedContainer[T]) =
openarrayProc2(arg)
openarrayProc2(exampleData) # compiles
conceptProc2(exampleData) # nim compiler crash
0 (0 bytes)
```cpp
```
2024-07-21T22:35:48
2024-07-21T22:35:49
0 (0 bytes)
```cpp
```
2024-07-21T22:35:52
2024-07-21T22:35:53
0 (0 bytes)
```cpp
```
2024-07-21T22:35:55
2024-07-21T22:35:56
0 (0 bytes)
```cpp
```
2024-07-21T22:35:59
2024-07-21T22:35:59
0 (0 bytes)
```cpp
```
2024-07-21T22:36:02
2024-07-21T22:36:02
0 (0 bytes)
```cpp
```
2024-07-21T22:36:04
2024-07-21T22:36:05
0 (0 bytes)
```cpp
```
2024-07-21T22:36:07
2024-07-21T22:36:07
0 (0 bytes)
```cpp
```
2024-07-21T22:36:09
2024-07-21T22:36:09
11.4.0
14.0.0
20.4
2024-07-21T22:35:22Z
1
nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
:robot: Bug found in 23 minutes
bisecting 8
commits at 0
commits per second
Description
Mixing generic concepts with openarray leads to compiler crashes. The compiler matches compatible concept container types with the equivalent openarry type but mishandles them. Procs taking the concept type, when passed an openarray, generate bad code. Procs taking an openarray, when passed a concept, crash the nim compiler.
Example
Nim Version
Nim Compiler Version 2.0.8 [Linux: amd64] Compiled at 2024-07-03 Copyright (c) 2006-2023 by Andreas Rumpf
git hash: 5935c3bfa9fec6505394867b23510eb5cbab3dbf active boot switches: -d:release
Current Output
Expected Output
Possible Solution
No response
Additional Information
No response