Commit 6151d2e
committed
instantiate generics using the passed functions
This patch adds simple type level matching for the doc functions
and signatures allowing to instantiate generics based on the passed
functions.
The following code demonstrates a generic type instantiated by this
feature.
```lua
---@param a number
---@return string
local function tostr(a)
return tostring(a)
end
---@Generic T, U
---@param x T
---@param f fun(x: T): U
---@return U
local function apply(x, f)
return f(x)
end
--"a" is inferred as a string.
a = apply(3, tostr)
```1 parent a94b0bb commit 6151d2e
File tree
2 files changed
+26
-2
lines changed- crates/code_analysis/src/semantic/instantiate
2 files changed
+26
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
Lines changed: 24 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
182 | 192 | | |
183 | 193 | | |
184 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
185 | 207 | | |
186 | 208 | | |
187 | 209 | | |
| |||
0 commit comments