yi-editor / yi-editor.github.com

Official documentation files
2 stars 8 forks source link

Fix precedence bug #22

Closed dariusf closed 6 years ago

dariusf commented 6 years ago

Subtle bug with the OO post: proto self { ... } is parsed as proto (self { ... }), but what is meant is (proto self) { ... }. With the former, we can't call overridden methods from the overriding object.

Minimal example:

data Thing = Thing {
  a :: String,
  b :: String
} deriving (Show)

proto :: Thing -> Thing
proto self = Thing {
  a = "original a " ++ b self,
  b = "original b"
}

base :: Thing
base = fix proto

proto' :: Thing -> Thing
proto' self = (proto self) { b = "new b" }

derived :: Thing
derived = fix proto'

-- without explicit parens, `b derived` wrongly returns "original b";
-- with, it returns "new b"