-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 calls in generic bodies, delay typecheck when no overloads match #22029
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0b50e59
sacrifice "tgenericshardcases" for working statics
metagn 9466308
legacy switch for CI, maybe experimental later
metagn 0fbd763
convert to experimental
metagn 79f0082
apparently untyped needs the experimental switch
metagn 8353d05
try special case call semcheck
metagn 5b545e1
try fix
metagn 3c32cb7
fix compilation
metagn c697132
final cleanup, not experimental, make `when` work
metagn 6a5a41f
remove last needed use of untyped
metagn f7fccfa
fix unused warning in test
metagn 790bf15
remove untyped feature
metagn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Cases that used to only work due to weird workarounds in the compiler | ||
# involving not instantiating calls in generic bodies which are removed | ||
# due to breaking statics. | ||
# The issue was that these calls are compiled as regular expressions at | ||
# the generic declaration with unresolved generic parameter types, | ||
# which are special cased in some places in the compiler, but sometimes | ||
# treated like real types. | ||
|
||
block: | ||
type Base10 = object | ||
|
||
func maxLen(T: typedesc[Base10], I: type): int8 = | ||
when I is uint8: | ||
3 | ||
elif I is uint16: | ||
5 | ||
elif I is uint32: | ||
10 | ||
elif I is uint64: | ||
20 | ||
else: | ||
when sizeof(uint) == 4: | ||
10 | ||
else: | ||
20 | ||
|
||
type | ||
Base10Buf[T: SomeUnsignedInt] = object | ||
data: array[maxLen(Base10, T), byte] | ||
len: int8 | ||
|
||
var x: Base10Buf[uint32] | ||
doAssert x.data.len == 10 | ||
var y: Base10Buf[uint16] | ||
doAssert y.data.len == 5 | ||
|
||
import typetraits | ||
|
||
block thardcases: | ||
proc typeNameLen(x: typedesc): int {.compileTime.} = | ||
result = x.name.len | ||
macro selectType(a, b: typedesc): typedesc = | ||
result = a | ||
|
||
type | ||
Foo[T] = object | ||
data1: array[T.high, int] | ||
data2: array[typeNameLen(T), float] | ||
data3: array[0..T.typeNameLen, selectType(float, int)] | ||
|
||
type MyEnum = enum A, B, C, D | ||
|
||
var f1: Foo[MyEnum] | ||
var f2: Foo[int8] | ||
|
||
doAssert high(f1.data1) == 2 # (D = 3) - 1 == 2 | ||
doAssert high(f1.data2) == 5 # (MyEnum.len = 6) - 1 == 5 | ||
|
||
doAssert high(f2.data1) == 126 # 127 - 1 == 126 | ||
doAssert high(f2.data2) == 3 # int8.len - 1 == 3 | ||
|
||
static: | ||
doAssert high(f1.data1) == ord(C) | ||
doAssert high(f1.data2) == 5 # length of MyEnum minus one, because we used T.high | ||
|
||
doAssert high(f2.data1) == 126 | ||
doAssert high(f2.data2) == 3 | ||
|
||
doAssert high(f1.data3) == 6 # length of MyEnum | ||
doAssert high(f2.data3) == 4 # length of int8 | ||
|
||
doAssert f2.data3[0] is float |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change exists in this PR for the sole purpose of making
T; U: static T
work (though might be more correct anyway). In any case the compiler treatsstatic T
the same asstatic foo()
and evaluates it as a constant expression which returnsstatic[T]
.static[T]
on the other hand goes throughsemStaticType
insemtypes
which doesn't have a reason to fail with generic params.One might think to add
elif op.id == ord(wStatic): result = semStaticType(...)
here instead, but this might not be correct and could break some code and I don't want to complicate this PR.Edit: I believe this also fixes #15760, will add test casedoesn't