Skip to content

Commit cc8c3d3

Browse files
edorianpronskiy
authored andcommitted
Type inference example without edge cases
`int + int` in PHP is `int|float`
1 parent fc9acb3 commit cc8c3d3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

source/_posts/2025-08-05-compile-generics.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,13 @@ As noted above, though, typing against a generic that is part of a union, like `
332332
Type inference is a feature of many heavily typed languages where the compiler or engine can "figure out" what the type of something is supposed to be based on context. As a trivial example:
333333

334334
```php
335-
function add(int $x, int $y)
335+
function concat(string $x, string $y)
336336
{
337-
return $x + $y;
337+
return $x . $y;
338338
}
339339
```
340340

341-
It's readily obvious that the return type of that function is `int`, so a type inference engine will fill that in for you automatically.
341+
It's readily obvious that the return type of that function is `string`, so a type inference engine will fill that in for you automatically.
342342

343343
That would be very helpful for Generics, especially if runtime Generics ever became possible.
344344

0 commit comments

Comments
 (0)