This repository was archived by the owner on Apr 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Semantics
Seyedamirhossein Hesamian edited this page Dec 27, 2021
·
7 revisions
Semantic rules:
- Class called
Driver
should not have any formals because it is the entry point
// Good
class Driver() { }
// Bad
class Driver(foo: String) { }
- No shadowing of variables whatsoever
// Good
class Foo(bar: String) {
{ var baz: Int = 3 }
}
// Bad
class Foo(foo: String) {
{ var foo: Int = 3 }
}
- Names in typed arms should be unique
// Good
class Foo() {
match "" with {
case x: String => "hello world!",
case y: String => "hello world!",
case null => null
}
}
// Bad
class Foo() {
match "" with {
case x: String => "hello world!",
case x: String => "hello world!",
case null => null
}
}
- Upon overriding a function, the formal types should be superset equals of parent level formal types
// Good
class Foo() extends IO() {
def bar(f: Foo) : String = null
}
class Driver() extends Foo() {
override def bar(f: Driver) : String = null
}
// Bad
class Foo() extends IO() {
def bar(f: Foo) : String = null
}
class Driver() extends Foo() {
override def bar(f: IO) : String = null
}
- Match arms should narrow down that type and not broaden it
// Good
class Foo(foo: Bar) {
match foo with {
case x: String => "hello world!",
case y: String => "hello world!",
case null => null
}
}
// Bad
class Foo(foo: Bar) {
match "" with {
case x: String => "hello world!",
case x: String => "hello world!",
case null => null
}
}
- No duplicate class name
-
Any
is the root type - If a class does not extend any other class, then it is implicitly extending
Any