Skip to content

Fix type() with a non-type base crashing when the error message is read - #1319

Open
jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/type-non-type-base
Open

jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/type-non-type-base

Conversation

@jseop-lim

Copy link
Copy Markdown
Contributor

Description

Part of #1291 (item 2).

TypeNode.calculateMetaclass checks that each base is an acceptable base type before it compares metaclasses, and raises TYPE_IS_NOT_ACCEPTABLE_BASE_TYPE with %N for a base that is not a type. Formatting that message throws UnsupportedSpecializationException, so reading the message ends the process. CPython's _PyType_CalculateMetaclass compares the metaclasses first and rejects a non-type base later with bases must be types.

AS-IS

>>> type('X', (3,), {})
com.oracle.truffle.api.dsl.UnsupportedSpecializationException: Unexpected values provided for ...
(process exits with status 1)

TO-BE

>>> type('X', (3,), {})
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
>>> type('X', (object(),), {})
TypeError: bases must be types

(matching CPython)

Changes

  • In calculateMetaclass, run the metaclass comparison over all bases first, then reject a base that is not a type with bases must be types and an unacceptable type as before.
  • Add BASES_MUST_BE_TYPES to ErrorMessages.
  • Add tests to tests/test_type.py.

Testing

mx python-jvm on darwin-aarch64, then mx graalpytest on test_type.py (the new test fails on the unpatched build and passes with the fix) and the tagged test_types (107 passed). mx python-checkcopyrights, mx eclipseformat and mx checkstyle are clean.

type('X', (3,), {}) raised the 'not an acceptable base type' error for
the non-type base, and formatting that message with %N crashed with an
UnsupportedSpecializationException. Compare the metaclasses first, as
CPython does, and reject a non-type base with 'bases must be types'.

Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 17, 2026

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

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant