Commit de18973
committed
Prevent
If a global variable is not annotated, and there's an assignment to it
in a generic function, there's a chance that references to generic parameters
will end up in its type.
This commit fixes the situation by skipping a type from a particular assignment
if it contains generic references.
This is a rather simplistic implementation. We could be smarter about it:
it's possible to analyze generics that're referenced from a type and replace
them with their bounds:
```lua
--- @Generic T: Bound
--- @param x T
function foo(x)
-- After this commit, `globalVar` will have type `undefined` in other files;
-- instead, we can infer it as `Bound`.
globalVar = x
end
```
However, this will require saving bounds to a global context,
and lazily replacing them later. I've decided to leave it as is for now.TplRefs from escaping into types of global variables1 parent 689118d commit de18973
File tree
3 files changed
+76
-6
lines changed- crates/emmylua_code_analysis/src
- compilation/test
- semantic/infer
3 files changed
+76
-6
lines changedLines changed: 19 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
1174 | 1173 | | |
1175 | 1174 | | |
1176 | 1175 | | |
1177 | | - | |
1178 | | - | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
1179 | 1195 | | |
1180 | 1196 | | |
1181 | 1197 | | |
| |||
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
123 | 161 | | |
Lines changed: 19 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
347 | | - | |
348 | | - | |
349 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
350 | 358 | | |
351 | 359 | | |
352 | 360 | | |
| |||
365 | 373 | | |
366 | 374 | | |
367 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
368 | 384 | | |
369 | 385 | | |
370 | 386 | | |
| |||
0 commit comments