Coder Social home page Coder Social logo

Comments (5)

lrhn avatar lrhn commented on September 25, 2024 1

Try switching DartPad to use the beta or master channels (bottom right corner), and see if the issue goes away.
If it does, then it's already fixed.

If I do that, https://dartpad.dev/?id=0a04aa2c6b4ea7c668fb002b83fc91c3&channel=beta, then the error goes away from the beta channel and onwards.

from sdk.

eernstg avatar eernstg commented on September 25, 2024

I can't reproduce this behavior using this program (using the DartPad stable or main channel):

extension type HeightWidth(num size) implements num {
  HeightWidth operator /(num denominator) {
    final b = size / denominator;
    return HeightWidth(size / denominator);
  }

  HeightWidth operator *(num multiplier) {
    return HeightWidth(size * multiplier);
  }

  HeightWidth times(num multiplier) {
    return HeightWidth(size * multiplier);
  }

  String get asString => 'HeightWidth($size)';
}

final d_margin1 = HeightWidth(1); // Was undefined.
final HeightWidth d_margin05 = d_margin1 / 2;
final HeightWidth d_margin1025 = d_margin1 * 1.25;
final HeightWidth d_margin105 = d_margin1.times(1.5);

void main() {
  print('${d_margin05.asString}, '
      '${d_margin1025.asString}, '
      '${d_margin105.asString}');
}

This program is accepted, it runs, and the output seems to be as expected. (We have to use a name which isn't a member of Object because extension types can't redeclare such members, so we use asString where we would perhaps have preferred to use toString())

Perhaps your tool chain is too old? What's the version?

from sdk.

lrhn avatar lrhn commented on September 25, 2024

The only issue I see with the code is the typo:

final HeightWIdth d_margin1025 = d_margin1 *1.25;
    // This gives syntax error as it returns a double, not HeightWidth

The I in WIdth is capitalized.

That should not give a syntax error.

The declaration of d_margin1 is not in the example, so even without the typo, we can't run it as provided.

Can you provide a complete program which has this issue, say how you execute it, and show the actual error message that you get?

(Actually, if I fix the typo, add a d_margin1, and run it in dartpad.dev on the stable branch, the analyzer does show an error for the multiplication:

A value of type 'double' can't be assigned to a variable of type 'HeightWidth'.

That error is gone on the beta and master branches, so it's probably that bug in the analyzer which causes the error to be shown. It's only cosmetic, the compiler will accept the code. And if that is the issue here, it has been fixed.)

from sdk.

prabinlamsal19 avatar prabinlamsal19 commented on September 25, 2024

Thank you for the response.
I am really sorry for the typo while posting the issue here. The typo is not present in my editor. (I have updated the original post's spelling also.)

The same code that you are writing is giving me errors in Dartpad also. Please look at this screenshot.

image

from sdk.

prabinlamsal19 avatar prabinlamsal19 commented on September 25, 2024

It worked when I switched to the latest. Thanks for the trouble.

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.