You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The empty set is type compatible with any concrete set type.
So, binary operations with empty set literal and typed set should also work:
assert {} <= {1'u8}
Nim Version
Since nim 0.19.0 to devel, introduced in #7558
Directly tested version:
Nim Compiler Version 1.0.0 [Linux: amd64]
Compiled at 2024-04-11
Copyright (c) 2006-2019 by Andreas Rumpf
git hash: f7a8fc46c0012033917582eb740dc0343c093e35
active boot switches: -d:release
Nim Compiler Version 1.6.14 [Linux: amd64]
Compiled at 2023-06-27
Copyright (c) 2006-2023 by Andreas Rumpf
active boot switches: -d:release
Current Output
Error: internal error: invalid kind for firstOrd(tyEmpty)
Expected Output
# Code compiles, all asserts pass
Possible Solution
For operations only on empty set literal it is enough to add early return in toBitSet in compiler/nimsets.nim
proctoBitSet*(conf: ConfigRef; s: PNode): TBitSet=result=@[]
# Added early returnif s.len ==0:
return# Below is implementation from develvar first: Int128=Zerovar j: Int128=Zero
first =firstOrd(conf, s.typ.elementType)
bitSetInit(result, int(getSize(conf, s.typ)))
for i in0..<s.len:
if s[i].kind == nkRange:
j =getOrdValue(s[i][0], first)
while j <=getOrdValue(s[i][1], first):
bitSetIncl(result, toInt64(j - first))
inc(j)
else:
bitSetIncl(result, toInt64(getOrdValue(s[i]) - first))
Additional Information
No response
The text was updated successfully, but these errors were encountered:
I agree that it may be acceptable to reject binary operations between empty set literal and typed set, because they are declared requiring same type is system, but consistency in cardinality on empty set literals is very useful for macros:
macrosomeMacro(body: untyped): untyped=templatehelperGenerateChecks(s: untyped): untyped=proccheck(val: int): bool=whencard(s) >0:
result=true# do some expensive checkelse:
result=false# do some short-circuitvar someSet =newNimNode(nnkCurly)
# fill someSet based on body, possibly emptyresult=getAst(helperGenerateChecks(someSet))
And binary operations on empty sets are useful when comparing two sets generated by macros
Description
Operations on built-in set literal
{}
cause compiler internal error.Code examples:
Also, according to manual
So, binary operations with empty set literal and typed set should also work:
Nim Version
Since nim
0.19.0
todevel
, introduced in #7558Directly tested version:
Current Output
Expected Output
Possible Solution
For operations only on empty set literal it is enough to add early return in
toBitSet
incompiler/nimsets.nim
Additional Information
No response
The text was updated successfully, but these errors were encountered: