Files
swift-mirror/test/expr/delayed-ident/static_func.swift
Doug Gregor 19759529db Allow delayed identifier expressions (.foo) with static variables and methods.
This allows expressions such as ".foo" and ".foo(1)" to refer to
static variables and static methods, respectively, as well as enum
cases. 

To get here, rework the parsing of delayed identifier expressions a
bit, so that the argument itself is part of the delayed argument
expression rather than a separate call expression. This simplifies
both the handling of patterns of this form and the type checker, which
can now user simpler constraints.

If we really want to support (.foo)(1), we can make that work, but it
seems unnecessary and perhaps confusing.


Swift SVN r10626
2013-11-21 06:24:06 +00:00

28 lines
631 B
Swift

// RUN: %swift -parse %s -verify
// Simple struct types
struct X1 {
static func create(i: Int) -> X1 { }
static func createGeneric<T>(d: T) -> X1 { }
static func notAFactory(i: Int) -> Int { }
}
// Static methods
var x1: X1 = .create(5)
x1 = .createGeneric(3.14159)
// Non-matching data members
x1 = .notAFactory(5) // expected-error{{'X1' is not identical to 'Int'}}
// Generic struct types
struct X2<T> {
static func create(t: T) -> X2 { }
static func createGeneric<U>(t: T, u:U) -> X2 { }
}
// Static methods
var x2a: X2 = .create(5)
x2a = .createGeneric(5, 3.14159)
var x2b: X2 = .createGeneric(5, 3.14159)