Skip to content

Expand scope of narrowing typecasts and fix issues - #117

Open
kjw142857 wants to merge 17 commits into
mainfrom
type-casting
Open

kjw142857 wants to merge 17 commits into
mainfrom
type-casting

Conversation

@kjw142857

@kjw142857 kjw142857 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

This PR expands on #89 to enhance narrowing typecasts as well as fixing some known limitations.

Changes:

  • Byte, short and char now are able to be narrowcasted using the Java 8 typecasting rules
  • Fixed a grammar rule which was causing errors when performing a non-primitive (reference) narrrowing typecast.
  • Fixed a bug where narrowing typecasts rounded numbers (e.g. double to int) instead of truncating them.
  • Fixed a bug which allowed compilation of illegal binary operations between disallowed types.
  • Fixed a bug where an extra line would be printed after every print statment.
  • Fixed a bug where some primitive types would not be printed correctly.
  • Fixed a bug where break in a switch statement in a loop would break the loop instead of the switch.
  • Fixed a bug where instantiation of abstract classes succeeding in compiling, and added checks that all abstract methods in an abstract class are eventually implemented by its descendant concrete classes.
  • Fixed a bug where field access to a parent class using the super keyword could not compile.
  • Fixed a bug where calling an inherited method could not compile.
  • Fixed a bug where field initialisation of arrays could not compile.
  • Fixed a bug where inheritance from an imported library discarded the details of the import.
  • Fixed a bug where a bare this keyword could not be parsed.

@kjw142857
kjw142857 requested a review from martin-henz October 27, 2026 14:02
@kjw142857 kjw142857 changed the title Expand scope of narrowing typecasts and fix truncation Expand scope of narrowing typecasts and fix issues Oct 27, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Coverage report

St.❔
Category Percentage Covered / Total
🟡 Statements
74.84% (+3.05% 🔼)
10085/13475
🟡 Branches
63.82% (+3.52% 🔼)
3477/5448
🟡 Functions
73.98% (+3.66% 🔼)
1791/2421
🟡 Lines
75.77% (+3.06% 🔼)
9414/12425
Show new covered files 🐣
St.❔
File Statements Branches Functions Lines
🟢
... / StrictMath.ts
100% 100% 100% 100%
🟡 jvm/utils/fdlibm.ts 71.9% 43.09% 100% 74.77%
🟢
... / Double.ts
100% 100% 100% 100%
🟢
... / Float.ts
100% 100% 100% 100%
🟢
... / castExpression.test.ts
100% 100% 100% 100%
🟢
... / literals.test.ts
100% 100% 100% 100%
🟢
... / switch.test.ts
100% 100% 100% 100%
🟢
... / inheritance.test.ts
100% 100% 100% 100%
Show files with reduced coverage 🔻
St.❔
File Statements Branches Functions Lines
🟢
... / compiler.ts
98.51% (-0.41% 🔻)
88.19% (+7.64% 🔼)
100%
98.92% (+0.07% 🔼)
🟢
... / constant-pool-manager.ts
98.86% (+0.15% 🔼)
91.67% (-2.78% 🔻)
96.77% (+0.22% 🔼)
98.85% (+0.15% 🔼)

Test suite run success

1867 tests passing in 78 suites.

Report generated by 🧪jest coverage report action from 90b0061

@kjw142857 kjw142857 mentioned this pull request Nov 3, 2026
Comment thread src/compiler/code-generator.ts Resolved
Comment thread src/compiler/code-generator.ts Resolved
Comment thread src/compiler/code-generator.ts Resolved
Comment thread src/compiler/code-generator.ts Resolved
@kjw142857
kjw142857 requested a review from kellywsq03 November 5, 2026 16:32
Comment thread src/compiler/code-generator.ts Resolved
Comment thread src/compiler/code-generator.ts Resolved
Comment thread src/compiler/code-generator.ts Resolved
Comment thread src/compiler/symbol-table.ts Resolved

BinaryExpression: (node: Node, cg: CodeGenerator) => {
const { left: left, right: right, operator: op } = node as BinaryExpression
if (op === '&&' || op === '||') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this section skips the operand type validations, so non-boolean operands are allowed and their truthiness is evaluated. i think Java only permits boolean or Boolean operands for the && or || operators.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

2 participants