Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat new Array(0) as immutable #19192

Merged
merged 2 commits into from
Dec 14, 2023
Merged

Conversation

liufengyun
Copy link
Contributor

@liufengyun liufengyun commented Dec 4, 2023

An array of size 0 is immutable, thus we can safely abstract them with the bottom value.

For the rules to be simple and understandable, we usually want to avoid such fine-tuning. However, given that we expect such code patterns to be rare and we want to avoid changes in the standard library, we fine-tune the analysis as a compromise.

Partly fixes #18882. The warnings in compiling tests/init-global/neg/t9312.scala goes down to 28 from 87.

An array of size 0 is immutable, thus we can safely abstract them with the bottom value.

For the rules to be simple and understandable, we usually want to avoid such fine-tuning. However,
given that we expect such code patterns to be rare and we want to avoid changes in the standard
library, we fine-tune the analysis as a compromise.
@liufengyun liufengyun marked this pull request as ready for review December 11, 2023 21:16
Copy link
Contributor

@olhotak olhotak left a comment

Choose a reason for hiding this comment

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

Othersize LGTM.

@@ -875,7 +875,7 @@ object Objects:
* @param ctor The symbol of the target constructor.
* @param args The arguments passsed to the constructor.
*/
def instantiate(outer: Value, klass: ClassSymbol, ctor: Symbol, args: List[ArgInfo]): Contextual[Value] = log("instantiating " + klass.show + ", outer = " + outer + ", args = " + args.map(_.value.show), printer, (_: Value).show) {
def instantiate(outer: Value, klass: ClassSymbol, ctor: Symbol, args: List[ArgInfo], inKlass: ClassSymbol): Contextual[Value] = log("instantiating " + klass.show + ", outer = " + outer + ", args = " + args.map(_.value.show), printer, (_: Value).show) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider removing inKlass: it is not used.

@liufengyun liufengyun enabled auto-merge December 14, 2023 23:28
@liufengyun liufengyun merged commit 423cd6c into scala:main Dec 14, 2023
17 checks passed
@liufengyun liufengyun deleted the fix-i18882 branch December 14, 2023 23:51
@Kordyjan Kordyjan added this to the 3.4.0 milestone Dec 20, 2023
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.

-Ysafe-init-global not working with Scala 2 library TASTy
3 participants