(declaredType *Type, assignedType *Type)
| 2388 | } |
| 2389 | |
| 2390 | func (c *Checker) getAssignmentReducedTypeWorker(declaredType *Type, assignedType *Type) *Type { |
| 2391 | filteredType := c.filterType(declaredType, func(t *Type) bool { |
| 2392 | return c.typeMaybeAssignableTo(assignedType, t) |
| 2393 | }) |
| 2394 | // Ensure that we narrow to fresh types if the assignment is a fresh boolean literal type. |
| 2395 | reducedType := filteredType |
| 2396 | if assignedType.flags&TypeFlagsBooleanLiteral != 0 && isFreshLiteralType(assignedType) { |
| 2397 | reducedType = c.mapType(filteredType, c.getFreshTypeOfLiteralType) |
| 2398 | } |
| 2399 | // Our crude heuristic produces an invalid result in some cases: see GH#26130. |
| 2400 | // For now, when that happens, we give up and don't narrow at all. (This also |
| 2401 | // means we'll never narrow for erroneous assignments where the assigned type |
| 2402 | // is not assignable to the declared type.) |
| 2403 | if c.isTypeAssignableTo(assignedType, reducedType) { |
| 2404 | return reducedType |
| 2405 | } |
| 2406 | return declaredType |
| 2407 | } |
| 2408 | |
| 2409 | func (c *Checker) typeMaybeAssignableTo(source *Type, target *Type) bool { |
| 2410 | if source.flags&TypeFlagsUnion == 0 { |
no test coverage detected