Coder Social home page Coder Social logo

Comments (11)

stereotype441 avatar stereotype441 commented on August 17, 2024 1

@Hixie

This is just about how the type on the RHS of ?? is inferred, not how the type of the whole expression is inferred, right?

Correct, it's just about how the RHS of ?? is inferred.

As in:

T? nope<T>() => null;

void main() {
  var x = nope<int>() ?? ''; // x is inferred to be Object rather than int, even after this change
}

Yes. In fact, this code is unaffected by the change for two reasons: (1) because the type of the RHS ('') is always String, regardless of the context in which it's inferred, and (2) since the variable declaration has an implicit type, the context for the whole if-null expression nope<int>() ?? '' is _, not dynamic.

from sdk.

itsjustkevin avatar itsjustkevin commented on August 17, 2024

@Hixie @grouma @vsmenon for review as a follow on to #55418.

from sdk.

Hixie avatar Hixie commented on August 17, 2024

This is just about how the type on the RHS of ?? is inferred, not how the type of the whole expression is inferred, right?

As in:

T? nope<T>() => null;

void main() {
  var x = nope<int>() ?? ''; // x is inferred to be Object rather than int, even after this change
}

Assuming I understand correctly, SGTM.

from sdk.

vsmenon avatar vsmenon commented on August 17, 2024

lgtm

from sdk.

lrhn avatar lrhn commented on August 17, 2024

(Shouldn't the context type of e2 be NonNull(S) where S is the static type of e1, not just the type itself? It does seem to consistently be the static type itself, but that means that

void main() async {
  List<int>? maybeList = null as dynamic;
  var x = maybeList ?? (await Future.value([]));
  print([x].runtimeType);
}

gives x a static type of List<int>? for no good reason. Probably not something to fix in this "consistency CL", since it's something both implementations agree on today.)

from sdk.

stereotype441 avatar stereotype441 commented on August 17, 2024

@lrhn

(Shouldn't the context type of e2 be NonNull(S) where S is the static type of e1, not just the type itself? It does seem to consistently be the static type itself, but that means that

void main() async {
  List<int>? maybeList = null as dynamic;
  var x = maybeList ?? (await Future.value([]));
  print([x].runtimeType);
}

gives x a static type of List<int>? for no good reason.

Yeah, considering that this is an example of an aspirational context, I agree. It makes sense to do something as close as possible to what we think the user probably wants, and NonNull(S) seems like a better model of what the user probably wants than S.

Probably not something to fix in this "consistency CL", since it's something both implementations agree on today.)

Agreed 😃

from sdk.

stereotype441 avatar stereotype441 commented on August 17, 2024

@grouma ping

from sdk.

grouma avatar grouma commented on August 17, 2024

cc @leonsenft who will handle breaking change requests for ACX going forward.

from sdk.

leonsenft avatar leonsenft commented on August 17, 2024

LGTM assuming

A prototype of this change caused zero test failures in Google's internal codebase

holds.

from sdk.

stereotype441 avatar stereotype441 commented on August 17, 2024

LGTM assuming

A prototype of this change caused zero test failures in Google's internal codebase

holds.

I will recheck before landing the change.

from sdk.

itsjustkevin avatar itsjustkevin commented on August 17, 2024

@stereotype441 lock it in!

from sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.