Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Mathias Jeppesen
PLUS
Mathias Jeppesen
Courses Plus Student 3,199 Points

Compiler doesn't detect wrongful setup of default implementation

The default implementation of fullname in the video example, which is dependant on firstname and lastname, got me thinking what would happen if ALL the variables were dependant on each other.

I set up this example:

protocol Number {
    var valueA: Int { get }
    var valueB: Int { get }
}

extension Number {
    var valueA: Int {
        return valueB + 2
    }
    var valueB: Int {
        return valueA - 2
    }
}

class NumberGenerator: Number {}

let numberGenerator = NumberGenerator()

The example is very simple, but shows my point that the compiler believes that it can generate values for respectively valueA and valueB. But seeing that the computed variables depend on each other this can never happen.

Can someone tell me if I'm wrong or wether there is something I'm missing or have misunderstood - If not, I guess the point is just to be aware that this can cause an error and that the compiler won't be able to tell where error occurs.