This repository was archived by the owner on Feb 23, 2023. It is now read-only.
Commit 6bff1ab
authored
numbers: Add proper safety to operator overloading (#204)
* numbers: Add null assertions to operator overloading
When operator overloading functions are called, then unfortunately
work when the left hand side of the operation is nullable (only inside
class properties), like this:
```ts
class BigInt extends Uint8Array {
@operator('+')
plus(other: BigInt): BigInt {
// ...
}
}
class Wrapper {
public constructor(
public n: BigInt | null
) {}
}
let x = BigInt.fromI32(2);
let y: BigInt | null = null;
// x + y; // give compile time error about nullability
let wrapper = new Wrapper(y);
wrapper.n = wrapper.n + x; // doesn't give compile time errors as it should
```
In our case it would break in graph-node's runtime side because these
operator implementations are written there in the host-exports.
These checks only exist while the compiler doesn't catch this itself.
* 0.22.0-alpha.31 parent c40be8c commit 6bff1ab
2 files changed
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
| 146 | + | |
145 | 147 | | |
146 | 148 | | |
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
| 152 | + | |
150 | 153 | | |
151 | 154 | | |
152 | 155 | | |
153 | 156 | | |
154 | 157 | | |
| 158 | + | |
155 | 159 | | |
156 | 160 | | |
157 | 161 | | |
| |||
161 | 165 | | |
162 | 166 | | |
163 | 167 | | |
| 168 | + | |
164 | 169 | | |
165 | 170 | | |
166 | 171 | | |
| |||
319 | 324 | | |
320 | 325 | | |
321 | 326 | | |
| 327 | + | |
322 | 328 | | |
323 | 329 | | |
324 | 330 | | |
325 | 331 | | |
326 | 332 | | |
| 333 | + | |
327 | 334 | | |
328 | 335 | | |
329 | 336 | | |
330 | 337 | | |
331 | 338 | | |
| 339 | + | |
332 | 340 | | |
333 | 341 | | |
334 | 342 | | |
335 | 343 | | |
336 | 344 | | |
| 345 | + | |
337 | 346 | | |
338 | 347 | | |
339 | 348 | | |
| |||
369 | 378 | | |
370 | 379 | | |
371 | 380 | | |
| 381 | + | |
372 | 382 | | |
373 | 383 | | |
374 | 384 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
0 commit comments