Skip to content

Reject an integer returned from a real Jass function - #1491

Merged
Frotty merged 4 commits into
masterfrom
reject-jass-int-return-as-real
Oct 17, 2026
Merged

Frotty merged 4 commits into
masterfrom
reject-jass-int-return-as-real

Conversation

@Frotty

@Frotty Frotty commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Jass code accepts an integer wherever a real is expected, returns included. pjass rejects an integer returned from a function declared to return a real ("Cannot convert returned value from integer to real"), so such a function only got through a build when every call to it was inlined. Inlining removed the return, and with it the conversion, so f(n) / m became the integer division n / m.

  • The type check now reports an integer (a variable, an expression or a literal) returned from a real function in Jass code: "Cannot convert returned value from integer to real: a function which returns real must return a real, for example I2R(...)". Jass types derived from integer or real (type myint extends integer) count as integer or real, as they do for pjass. Integers stored into or passed as reals are still accepted, as pjass accepts them.
  • For a legacy target (pre-1.24, legacyJassTypeChecks, no pjass) it is a warning, like the other Jass return mismatches. The IM translation, which still has the Jass types, flags such a function and the inliner leaves it a call: inlined, the integer would land in an operand. I chose that over splicing an explicit conversion because it changes nothing for valid code. How the legacy engine treats such a return is unmeasured.
  • The test harness now skips pjass for a legacy target, as a build does.

Measured on the 3.0.0 client (3.0.0.24268). The probe is function f takes integer n returns real / return n and f(n) / m with n = 7 and m = 2, read from an array at run time and built with -inline -localOptimizations in Jass mode:

  • old compiler: emits set a = n / m and gives 3 (an integer division; 3.5 expected)
  • new compiler: the build stops at the probe with the error above

Tests: CompilationUnitTests (int, literal and derived-type returns are errors, a warning for legacy targets, int stored or passed as real is OK) and OptimizerTests.inlinerKeepsALegacy(Derived)IntReturnedAsRealACall (red without the change). CompilationUnitTests, BugTests and OptimizerTests pass locally on Windows. The change has no host-specific code; other platforms were not run locally.

pjass rejects it, so only an inlined call compiled, and there f(n) / m became the integer division n / m. Report it at type check as for Wurst source; a warning for legacy targets.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T19:43:22.359071Z 2ecd56d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3069aaa88

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…does

A legacy target accepts the return with a warning. The inliner leaves such a function a call, where the integer becomes the declared real. The test harness skips pjass for a legacy target, as a build does.
type myint extends integer returned as real, and an integer returned as type myreal extends real, are the same pjass error.
@Frotty

Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 873d354b95

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The IM names a derived native type only by its own name, so the inliner could not tell type myint extends integer from another type. The translation, which has the Jass types, marks such a function, and the inliner keeps it a call.
@Frotty

Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 2ecd56de8f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty
Frotty merged commit d9c0568 into master Oct 17, 2026
2 checks passed
@Frotty
Frotty deleted the reject-jass-int-return-as-real branch October 17, 2026 19:51
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.

1 participant