prevent stack overflows from faulty user-defined constructor methods#59506
Merged
topolarity merged 4 commits intoJuliaLang:masterfrom Sep 17, 2025
Conversation
`Base` code often assumes that a constructor will return a value of the stated type. This is false, cross-reference issue JuliaLang#42372. This change prevents several stack overflows that arise when a generic method is called with a newly-defined type with such a weird constructor for some `Base`-defined type.
Member
Author
|
The trimming CI failure is issue #59507. |
topolarity
approved these changes
Sep 17, 2025
Member
topolarity
left a comment
There was a problem hiding this comment.
Good find. Indeed, these implementations assume that these will reach a base case.
xal-0
pushed a commit
to xal-0/julia
that referenced
this pull request
Sep 30, 2025
…uliaLang#59506) `Base` code often assumes that a constructor will return a value of the stated type. This is false, cross-reference issue JuliaLang#42372. This change prevents several stack overflows that arise when a generic method is called with a newly-defined type with such a weird constructor for some `Base`-defined type.
nsajko
added a commit
to nsajko/julia
that referenced
this pull request
Jan 29, 2026
Due to issue JuliaLang#42372, it can not be assumed that a constructor call will return a value of the requested type. Enforce that assumption in code where it matters. Example stack overflows that this change prevents: ```julia struct FaultyInt <: Integer end # new `Int`-like function Base.Int(x::FaultyInt) x end # invalid constructor iterate("", FaultyInt()) # overflows the stack isvalid("", FaultyInt()) # overflows the stack struct MyString <: AbstractString # valid new subtype of `AbstractString` str::String end isvalid(MyString(""), FaultyInt()) # overflows the stack codeunit(MyString(""), FaultyInt()) # overflows the stack ``` Follow up on PR JuliaLang#59506.
adienes
pushed a commit
that referenced
this pull request
Jan 30, 2026
#60876) Due to issue #42372, it can not be assumed that a constructor call will return a value of the requested type. Enforce that assumption in code where it matters. Example stack overflows that this change prevents: ```julia struct FaultyInt <: Integer end # new `Int`-like function Base.Int(x::FaultyInt) x end # invalid constructor iterate("", FaultyInt()) # overflows the stack isvalid("", FaultyInt()) # overflows the stack struct MyString <: AbstractString # valid new subtype of `AbstractString` str::String end isvalid(MyString(""), FaultyInt()) # overflows the stack codeunit(MyString(""), FaultyInt()) # overflows the stack ``` Follow up on PR #59506.
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.
Basecode often assumes that a constructor will return a value of the stated type. This is false, cross-reference issue #42372.This change prevents several stack overflows that arise when a generic method is called with a newly-defined type with such a weird constructor for some
Base-defined type.