Repository navigation
Fix compiler crash on a missing cimported module attribute inside a function - #8099
Open
Thanatos9404 wants to merge 1 commit into
Open
Thanatos9404 wants to merge 1 commit into
Thanatos9404 wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6009.
Inside a function,
x = cmath.no_such_func()(withcimport libc.math as cmath) reported "cimported module has no attribute 'no_such_func'" and then crashed inAnalyseExpressionsTransformwithAttributeError: 'NoneType' object has no attribute 'type'.AttributeNode.infer_typecallsanalyse_as_cimported_attribute_node. In the error branch, that returns the node itself with noentry, andinfer_typethen readsnode.entry.type. Module-level uses don't go through local type inference, which is whytests/errors/cimport_attributes.pyxdidn't catch it.The fix:
infer_typenow returnserror_typefor that case.analyse_typesreports it once, as it does at module level.The new error test
tests/errors/cimport_attribute_infer_GH6009.pyxcovers 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 oftests/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.