From b95627e24201bccbd3d1ee04f9101772504e9c2f Mon Sep 17 00:00:00 2001 From: Volker Dusch <247397+edorian@users.noreply.github.com> Date: Thu, 7 Aug 2025 18:38:10 +0200 Subject: [PATCH] Type inference example without edge cases `int + int` in PHP is `int|float` --- source/_posts/2025-08-05-compile-generics.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/_posts/2025-08-05-compile-generics.md b/source/_posts/2025-08-05-compile-generics.md index 634144f2..c0c7891a 100644 --- a/source/_posts/2025-08-05-compile-generics.md +++ b/source/_posts/2025-08-05-compile-generics.md @@ -332,13 +332,13 @@ As noted above, though, typing against a generic that is part of a union, like ` 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: ```php -function add(int $x, int $y) +function concat(string $x, string $y) { - return $x + $y; + return $x . $y; } ``` -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. +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. That would be very helpful for Generics, especially if runtime Generics ever became possible.