Commit 2401bdf
Fix typeclass constraints dropped from polymorphic type annotations.
When a type variable stays polymorphic through an operator that
requires a typeclass constraint (+ requires number, < requires
comparable, ++ requires appendable), the constraint was lost during
type variable rewriting, producing `a -> a -> a` instead of
`number -> number -> number`.
Root cause: `resolveVariables` replaces constrained names (like
`number_0` or `comparable`) with arg variable names (like `arg_0`).
Then `rewriteTypeVariables` renames `arg_0` to `a`, losing the
constraint.
Fix: `rewriteTypeVariablesPreservingConstraints` builds a mapping
from resolved variable names back to their constraint names by
walking the inference cache bidirectionally. If a constrained name
maps to a generic (forward: `number_0 → arg_0`) or a generic maps
to a constrained name (reverse: `arg_0 → comparable`), the
constraint name is preserved during rewriting.
Before:
Elm.Op.plus a b → addBoth : a -> a -> a
Elm.Op.lt a b → compareBoth : a -> a -> Bool
Elm.Op.append a b → appendBoth : a -> a -> a
After:
Elm.Op.plus a b → addBoth : number -> number -> number
Elm.Op.lt a b → compareBoth : comparable -> comparable -> Bool
Elm.Op.append a b → appendBoth : appendable -> appendable -> appendable
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 84c0f33 commit 2401bdf
2 files changed
Lines changed: 195 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1020 | 1020 | | |
1021 | 1021 | | |
1022 | 1022 | | |
1023 | | - | |
| 1023 | + | |
1024 | 1024 | | |
1025 | 1025 | | |
1026 | 1026 | | |
| |||
1286 | 1286 | | |
1287 | 1287 | | |
1288 | 1288 | | |
1289 | | - | |
1290 | | - | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
1291 | 1303 | | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
1292 | 1351 | | |
1293 | 1352 | | |
1294 | | - | |
| 1353 | + | |
1295 | 1354 | | |
1296 | 1355 | | |
1297 | | - | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
1298 | 1364 | | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
1299 | 1379 | | |
1300 | | - | |
1301 | | - | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
1302 | 1398 | | |
1303 | 1399 | | |
1304 | 1400 | | |
1305 | 1401 | | |
1306 | 1402 | | |
1307 | 1403 | | |
1308 | 1404 | | |
1309 | | - | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
1310 | 1411 | | |
1311 | 1412 | | |
1312 | | - | |
1313 | 1413 | | |
1314 | 1414 | | |
1315 | 1415 | | |
| |||
1326 | 1426 | | |
1327 | 1427 | | |
1328 | 1428 | | |
1329 | | - | |
| 1429 | + | |
1330 | 1430 | | |
1331 | 1431 | | |
1332 | 1432 | | |
| |||
1351 | 1451 | | |
1352 | 1452 | | |
1353 | 1453 | | |
1354 | | - | |
| 1454 | + | |
1355 | 1455 | | |
1356 | 1456 | | |
1357 | | - | |
| 1457 | + | |
1358 | 1458 | | |
1359 | 1459 | | |
1360 | 1460 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
274 | 357 | | |
275 | 358 | | |
276 | 359 | | |
| |||
0 commit comments