Skip to content

Enable method overloading and overriding#70

Merged
kjw142857 merged 37 commits into
mainfrom
method-overloading-overriding
May 28, 2026
Merged

Enable method overloading and overriding#70
kjw142857 merged 37 commits into
mainfrom
method-overloading-overriding

Conversation

@AprupKale
Copy link
Copy Markdown
Contributor

Enable running multiple classes in java-slang.

Enable method overloading and overriding to support code as follows:

public class Main {
  public void f(int x) {
    System.out.println("Instance int: " + x);
  }
  public void f(double x) {
    System.out.println("Instance double: " + x);
  }
  public static void main(String[] args) {
    Main obj = new Main();
    obj.f(5);
    obj.f(5.5);
  }
}

and

class Parent {
  public static void staticMethod() {
    System.out.println("Parent static method");
  }
  public void instanceMethod() {
    System.out.println("Parent instance method");
  }
}

class Child extends Parent {
  public static void staticMethod() {
    System.out.println("Child static method");
  }
  public void instanceMethod() {
    System.out.println("Child instance method");
  }
}

public class Main {
  public static void main(String[] args) {
    Parent.staticMethod(); // Parent static method
    Child.staticMethod(); // Child static method
    Parent ref = new Child();
    ref.instanceMethod(); // Child instance method
  }
}

@AprupKale AprupKale self-assigned this Apr 6, 2025
@AprupKale AprupKale added the enhancement New feature or request label Apr 6, 2025
@AprupKale AprupKale linked an issue Apr 6, 2025 that may be closed by this pull request
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 6, 2025

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
72.5% (-1.07% 🔻)
7408/10218
🔴 Branches
59.17% (-0.7% 🔻)
2480/4191
🟡 Functions
69.04% (-0.48% 🔻)
1320/1912
🟡 Lines
73.37% (-1.11% 🔻)
6974/9505
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟡
... / index.ts
70.56% (-1.12% 🔻)
47.31% (-2.31% 🔻)
91.67% (-3.99% 🔻)
79.47% (-1.59% 🔻)
🟢
... / compiler.ts
100%
83.33% (-9.52% 🔻)
100% 100%
🟢
... / symbol-table.ts
91.09% (-2.81% 🔻)
67.39% (-12.02% 🔻)
100%
90.58% (-3.05% 🔻)
🟡
... / code-generator.ts
68.27% (-19.97% 🔻)
61.04% (-16.58% 🔻)
65.43% (-27.9% 🔻)
69.11% (-19.35% 🔻)
🟡
... / binary-writer.ts
77.78% (-2.07% 🔻)
50% (-9.09% 🔻)
63.64% (+1.14% 🔼)
79.84% (-2.51% 🔻)

Test suite run success

1134 tests passing in 64 suites.

Report generated by 🧪jest coverage report action from 283510e

@martin-henz
Copy link
Copy Markdown
Member

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements support for SwitchStatement and CastExpression, covering grammar updates, AST extraction, type checking, and bytecode generation. It also enhances method invocation to support overloading, overriding, and super calls, and enables the compiler to handle multiple class files. Feedback highlights several critical issues, including incorrect usage of the in operator and filter method in TypeScript, flawed JVM offset patching for switch instructions, and a missing string collision check in switch statements. Additionally, the reviewer identified logic errors in the final method override checks and inconsistent package naming conventions that could lead to lookup failures.

Comment thread src/compiler/code-generator.ts Outdated
Comment thread src/compiler/code-generator.ts Outdated
Comment thread src/compiler/code-generator.ts Outdated
Comment thread src/compiler/code-generator.ts
Comment thread src/compiler/code-generator.ts
Comment thread src/compiler/symbol-table.ts
Comment thread src/ast/astExtractor/statement-extractor.ts Outdated
Comment thread src/compiler/code-generator.ts Outdated
Comment thread src/compiler/symbol-table.ts
kjw142857 and others added 8 commits May 20, 2026 08:47
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@kjw142857
Copy link
Copy Markdown
Contributor

LGTM, approved!

@kjw142857 kjw142857 self-requested a review May 28, 2026 00:09
@kjw142857 kjw142857 merged commit 6232b18 into main May 28, 2026
4 checks passed
@kjw142857 kjw142857 deleted the method-overloading-overriding branch May 28, 2026 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler/type checker: Support for inheritance needed

3 participants