Files
swift-mirror/test/Interpreter/conversions.swift
Chris Willmore 03a6190a1f <rdar://problem/19031957> Change failable casts from "as" to "as!"
Previously the "as" keyword could either represent coercion or or forced
downcasting. This change separates the two notions. "as" now only means
type conversion, while the new "as!" operator is used to perform forced
downcasting. If a program uses "as" where "as!" is called for, we emit a
diagnostic and fixit.

Internally, this change removes the UnresolvedCheckedCastExpr class, in
favor of directly instantiating CoerceExpr when parsing the "as"
operator, and ForcedCheckedCastExpr when parsing the "as!" operator.

Swift SVN r24253
2015-01-08 00:33:59 +00:00

17 lines
391 B
Swift

// RUN: %target-run-simple-swift | FileCheck %s
class B { func foo() { println("foo") } }
class D : B { func bar() { println("bar") } }
class G<T> : B { func bas() { println("bas") } }
// CHECK: foo
func up(d: D) { d.foo() }
// CHECK: bar
func down(b: B) { (b as! D).bar() }
// CHECK: bas
func down_generic(b: B) { (b as! G<Int>).bas() }
up(D())
down(D())
down_generic(G<Int>())