Commit 369aa0f
committed
Fix constrained generic struct/variant type parameters
looksLikeGenericTypeParams (compiler.zig) — the lookahead that decides
whether Name[...] after a type name is a generic-parameter list — only
accepted .ident/.comma inside the brackets, so a constrained parameter
(type Box[T: numeric] struct {...}) fell through to `else => return
false` and the whole declaration was never recognized as generic at
all, despite docs/language.md documenting the same constraint syntax
generic functions already support (isNamedFuncDecl's sibling scanner
already allowed ':'). Fixed by bringing the two scanners in line.
Once recognized as generic, the constraint was still never enforced:
instantiateGenericType built the concrete type args but never checked
them against the declared constraints, unlike generic function calls
(which already run checkTypeArgConstraints). Fixed by calling the same
check during type instantiation.1 parent c98155c commit 369aa0f
3 files changed
Lines changed: 55 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4018 | 4018 | | |
4019 | 4019 | | |
4020 | 4020 | | |
| 4021 | + | |
| 4022 | + | |
| 4023 | + | |
| 4024 | + | |
| 4025 | + | |
| 4026 | + | |
| 4027 | + | |
| 4028 | + | |
| 4029 | + | |
| 4030 | + | |
| 4031 | + | |
| 4032 | + | |
| 4033 | + | |
| 4034 | + | |
| 4035 | + | |
| 4036 | + | |
| 4037 | + | |
| 4038 | + | |
| 4039 | + | |
| 4040 | + | |
| 4041 | + | |
| 4042 | + | |
| 4043 | + | |
| 4044 | + | |
| 4045 | + | |
| 4046 | + | |
| 4047 | + | |
| 4048 | + | |
| 4049 | + | |
| 4050 | + | |
| 4051 | + | |
| 4052 | + | |
| 4053 | + | |
| 4054 | + | |
| 4055 | + | |
| 4056 | + | |
| 4057 | + | |
| 4058 | + | |
4021 | 4059 | | |
4022 | 4060 | | |
4023 | 4061 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1921 | 1921 | | |
1922 | 1922 | | |
1923 | 1923 | | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
1924 | 1931 | | |
1925 | 1932 | | |
1926 | 1933 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1270 | 1270 | | |
1271 | 1271 | | |
1272 | 1272 | | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
1273 | 1283 | | |
1274 | 1284 | | |
1275 | 1285 | | |
| |||
0 commit comments