Error message

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Error message

Marco S Hyman
Am I the only one who finds this error message odd?

        'Foo?' does not have a member named 'variable'.

in this code:

class Foo {
    var variable: Int = 42
}

var foo: Foo? = Foo()

if let bar = foo.variable { // error here -- forgot the ? after foo.
    println("foo.variable is \(bar)")
}

foo? does have a valid member named variable if it is not nil
foo.variable is bogus since foo is an optional.

Marc

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/D74278E0-4E94-48C3-B63E-B753B42C302C%40snafu.org.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Error message

Jens Alfke

On Feb 9, 2015, at 7:31 PM, Marco S Hyman <[hidden email]> wrote:

Am I the only one who finds this error message odd?

'Foo?' does not have a member named 'variable'.

It makes sense to me. “Foo?” is not the same as Foo; it’s shorthand for something like Optional<Foo>, which does not have a member named ‘variable’.

I guess the message would be clearer if it said something like “You forgot to unwrap ‘foo’”. I suppose that kind of polish will get added to the compiler over time; right now they still have bigger issues to work on…

—Jens

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/51211838-74AE-44D6-A1F0-508DA6811E7C%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.