diff --git a/CHANGELOG.md b/CHANGELOG.md index f1f7fad..eacbc09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,10 @@ History note: ## Unreleased -- No unreleased entries yet. +- Reject member functions named after their enclosing class and diagnose unsupported `this(...)` constructor delegation at compile time. +- Preserve declared, inferred, and generic return types from static method calls. +- Initialize singleton static members and dispatch their calls through class scope, including trailing-lambda calls. +- Update the language reference and OOP guide with constructor naming rules and typed static factory examples. ## 1.5.6 (2026-05-16) diff --git a/bin/generate_docs.sh b/bin/generate_docs.sh index b1e311d..94e5596 100755 --- a/bin/generate_docs.sh +++ b/bin/generate_docs.sh @@ -113,9 +113,10 @@ process_file() { # - [text](file.md) -> [text](#file.md) # - [text](dir/file.md) -> [text](#dir_file.md) # - [text](file.md#anchor) -> [text](#anchor) - # - Fix image links: [alt](../images/...) -> [alt](images/...) if needed, but none found yet. + # - Resolve site-root image URLs against the local site resources for embedding. cat "$full_path" | \ + perl -pe 's{(!\[[^\]]*\]\()/}{$1site/src/jsMain/resources/}g' | \ perl -pe 's/\[([^\]]+)\]\(([^)]+)\.md\)/"[$1](#" . ($2 =~ s|\/|_|gr) . ".md)"/ge' | \ perl -pe 's/\[([^\]]+)\]\(([^)]+)\.md#([^)]+)\)/[$1](#$3)/g' >> "$MERGED_MD" diff --git a/docs/OOP.md b/docs/OOP.md index ee33607..685f0a1 100644 --- a/docs/OOP.md +++ b/docs/OOP.md @@ -42,6 +42,12 @@ a _constructor_ that requires two parameters for fields. So when creating it wit Form now on `Point` is a class, it's type is `Class`, and we can create instances with it as in the example above. +A member function cannot have the same name as its enclosing class, including a +static member function. Constructors are declared in the class header; use the +class name to create another instance. `this(...)` and `this@Type(...)` do not +declare or delegate to secondary constructors. Local functions may shadow class +names according to the normal lexical scope rules. + ## Singleton Objects Singleton objects are declared using the `object` keyword. An `object` declaration defines both a class and a single instance of that class at the same time. This is perfect for stateless utilities, global configuration, or shared delegates. @@ -1042,6 +1048,25 @@ Static fields can be accessed from static methods via the class qualifier: assertEquals("bar", Test.getData() ) >>> void +Static calls preserve their declared or inferred return types, so their results +can be used directly in chained expressions or assigned without a type annotation. +Generic static factories also preserve the type inferred from their arguments: + + class StaticBox(val value: T) { + static fun of(value: T): StaticBox = StaticBox(value) + } + val box = StaticBox.of("hello") + assertEquals(5, box.value.length) + >>> void + +Named singleton objects also support static methods: + + object StaticGreeting { + static fun text(): String = "hello" + } + assertEquals(5, StaticGreeting.text().length) + >>> void + # Extension members Sometimes an existing type or named singleton object is missing some particular functionality that can be _added to it_ without rewriting its inner logic and without using its private state. In this case, _extension members_ can be used.