Files
swift-mirror/validation-test/compiler_crashers_2_fixed/0105-sr5050.swift
Slava Pestov 65c3565c2d Sema: Fix failure to produce diagnostics when 'is' casts are involved
When re-typechecking an expression during diagnostics, we begin by
erasing all the types in the expression. However, any expressions
created as part of applying the solution will remain.

CSGen was doing the wrong thing when it encountered EnumIsCaseExpr,
which can only appear in already-type checked ASTs.

Returning expr->getType() is not correct, because the type is not
yet set; returning a null type is intended to signal that a
diagnostic was already emitted, which causes Sema to stop
type checking.

The end result is that certain combinations of invalid code with
an 'is' cast nested inside would crash either the AST verifier
(with asserts on) or in SILGen (with asserts off), because we
would stop trying to diagnose the issue prematurely, and possibly
not emit a diagnostic at all.

Fixes <https://bugs.swift.org/browse/SR-5050> and
<rdar://problem/32487948>.
2017-06-13 20:19:43 -07:00

13 lines
187 B
Swift

// RUN: not %target-swift-frontend %s -typecheck
// REQUIRES: asserts
protocol P {}
func bar(p: P?) {
foo(p is String)
}
func foo<T>(_: T, _: T) {}
func foo<T>(_: T?, _: T?) {}