Skip to content

Fix compiler crash on a missing cimported module attribute inside a function - #8099

Open
Thanatos9404 wants to merge 1 commit into
cython:masterfrom
Thanatos9404:fix-cimported-attribute-infer-crash
Open

Thanatos9404 wants to merge 1 commit into
cython:masterfrom
Thanatos9404:fix-cimported-attribute-infer-crash

Conversation

@Thanatos9404

Copy link
Copy Markdown

Closes #6009.

Inside a function, x = cmath.no_such_func() (with cimport libc.math as cmath) reported "cimported module has no attribute 'no_such_func'" and then crashed in AnalyseExpressionsTransform with AttributeError: 'NoneType' object has no attribute 'type'.

AttributeNode.infer_type calls analyse_as_cimported_attribute_node. In the error branch, that returns the node itself with no entry, and infer_type then reads node.entry.type. Module-level uses don't go through local type inference, which is why tests/errors/cimport_attributes.pyx didn't catch it.

The fix:

  • Inference: infer_type now returns error_type for that case.
  • Error reporting: inference no longer reports the error itself. It can run several times per node, and the error was otherwise printed three times. analyse_types reports it once, as it does at module level.

The new error test tests/errors/cimport_attribute_infer_GH6009.pyx covers a call and a plain attribute assigned to locals. On master it fails with the compiler crash; with this change it passes, and so does the rest of tests/errors. The issue's two-file example (cimport bbug) now stops after its two expected errors.

I didn't have a C compiler available, so I didn't run the compile/run tests locally. This change only affects the branch that reports this error.

…unction

Type inference of a local assigned from a missing attribute of a
cimported module read the entry of the error node, which is None.
Infer error_type there, and report the error only once, from
analyse_types, instead of on every inference pass.

Closes cython#6009
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.

[BUG] Cython compiler crashes with AttributeError: 'NoneType' object has no attribute 'type'

1 participant