Skip to content

Unintended SafeValue Error #23424

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

JasonH53
Copy link

Test case is expected to emit output with --Ysafe-init-global, but it emits a safe-value internal error. It is temporarily placed in the pos-tasty folder.

@JasonH53
Copy link
Author

signed CLA

@Gedochao Gedochao requested review from liufengyun June 26, 2025 08:11
@JasonH53 JasonH53 force-pushed the init-global-warning branch from 3d644ef to 8c06f71 Compare July 6, 2025 22:18
@JasonH53 JasonH53 changed the title Added test case for init-global checker Unintended SafeValue Error Jul 6, 2025
@Gedochao Gedochao requested a review from noti0na1 July 7, 2025 11:57
@Gedochao Gedochao requested a review from olhotak July 7, 2025 12:00
case v: SafeValue if expr.symbol.is(Flags.Method) =>
withTrace(trace2) { call(v, expr.symbol, args = Nil, receiver = qualifier.tpe, superType = NoType) }
case _ =>
withTrace(trace2) { select(qual, expr.symbol, receiver = qualifier.tpe) }
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking, why not always dispatch to call if the symbol is a method.

If that is the case, maybe it's better to fix the extractor Call:

def unapply(tree: Tree)(using Context): Option[(Tree, List[List[Arg]])] =
tree match
case Apply(fn, args) =>
val argTps = fn.tpe.widen match
case mt: MethodType => mt.paramInfos
if (args.size != argTps.size)
report.warning("[Internal error] Number of arguments do not match number of argument types in " + tree.symbol.name)
val normArgs: List[Arg] = args.zip(argTps).map {
case (arg, _: ExprType) => ByNameArg(arg)
case (arg, _) => arg
}
unapply(fn) match
case Some((ref, args0)) => Some((ref, args0 :+ normArgs))
case None => None
case TypeApply(fn, targs) =>
unapply(fn)
case ref: RefTree if ref.tpe.widenSingleton.isInstanceOf[MethodicType] =>
Some((ref, Nil))
case _ => None

Copy link
Author

Choose a reason for hiding this comment

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

Great idea! Would that mean that we should change Call:

 case ref: RefTree if ref.symbol.is(Flags.Method) && ref.tpe.widenSingleton.isInstanceOf[MethodicType] =>
        Some((ref, Nil))

and leaving the def cases unchanged?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can try just keep if ref.symbol.is(Flags.Method).

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.

3 participants