Coder Social home page Coder Social logo

Comments (5)

osa1 avatar osa1 commented on July 28, 2024

Smaller repro:

class C {
  double m1 = 42;
}

main() {
  C c = new C();
  c?.m1 ??= 42;
}

This looks similar to #55341 which also had an unnecessary null check.

from sdk.

osa1 avatar osa1 commented on July 28, 2024

I wonder if this is a TFA bug, post-TFA kernel looks wrong. Before TFA:

class C extends core::Object {
  field core::double m1 = 42.0;

  synthetic constructor •() → test::C
    : super core::Object::•()
    ;

  static method _#new#tearOff() → test::C
    return new test::C::•();
}

static method main() → dynamic {
  test::C c = new test::C::•();

  let final test::C #t1 = c
    in #t1 == null
         ?{core::double?} null
         : #t1.{test::C::m1}{core::double} == null ?{core::double} #t1.{test::C::m1} = 42.0 : null;
}

After TFA:

static method main() → dynamic {
  test::C c = new test::C::•();
  let final test::C #t1 = c in _in::unsafeCast<core::double?>(_in::unsafeCast<core::double>( block {
     #t1.{test::C::m1}{core::double};
  } =>null));
}

The problematic part is unsafeCast<double>(block { ... } => null), which tries to cast null to double.

@alexmarkov is my reading of the kernel correct? Could this be a TFA bug?

from sdk.

alexmarkov avatar alexmarkov commented on July 28, 2024

Kernel AST before TFA doesn't look correct:

?{core::double} #t1.{test::C::m1} = 42.0 : null

The static type of this ?: is double, while it can result in null. When pruning this expression, TFA keeps its static type by inserting unsafeCast (as changing the static type may alter semantics of enclosing expressions).

So the problem is likely in CFE or in another transformation prior to TFA.

/cc @johnniwinther @chloestefantsova

from sdk.

johnniwinther avatar johnniwinther commented on July 28, 2024

@chloestefantsova Is this the same problem that you fixed today?

from sdk.

osa1 avatar osa1 commented on July 28, 2024

Note: d4d7884 didn't fix this issue, repro works with the current main (671f271).

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.