Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial exercice 10 failure #24

Closed
leinadsepol opened this issue Sep 27, 2018 · 1 comment
Closed

Tutorial exercice 10 failure #24

leinadsepol opened this issue Sep 27, 2018 · 1 comment

Comments

@leinadsepol
Copy link

leinadsepol commented Sep 27, 2018

In tutorial for exercice n°10:

Now, let's write the mutable version. Notice the keywords 'mutable' placed in front of the field and the method. this.!field = value modifies object in place, much like in any other programming language.

mutable class Point {mutable x: Int, y: Int} {
    mutable fun incrX(): void {
      // TODO: increment the field 'x' by 1
      // HINT: 'this.!x = value' sets the field 'x' to 'value'
      
    }
}

A compilation error is returned regardless of the expression tested with run:

File "playground.sk", line 1, characters 15-19:
In 'Point's version of the member '!=' inherited from 'Equality'
1 | mutable class Point {mutable x: Int, y: Int} {
  |               ^^^^^
2 |   mutable fun incrX(): void {
File "tests/runtime/prelude/core/traits/Equality.sk", line 26, characters 12-13:
Cannot call this method on a readonly object
24 |
25 |   overridable readonly fun !=(other: inst): Bool {
26 |     !(this == other)
   |            ^^
27 |   }
File "playground.sk", line 13, characters 7-8:
Try annotating '==' method as 'readonly'
11 | extension class Point uses Equality, Show {
12 |   // Defining equality for a Point
13 |   fun ==(other: this): Bool {
   |       ^^
14 |     other.x == this.x && other.y == this.y    
@pikatchu
Copy link
Collaborator

Thanks a lot for flagging this!

So the problem is that those two functions have been made "readonly" in the standard lib, and we forgot to update the tutorial.

I fixed the problem and pushed a new version of the site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants