Coder Social home page Coder Social logo

Comments (1)

lrhn avatar lrhn commented on July 20, 2024

I think the errors might be surprising, but not completel;y unexplainable.

The const [b] is invalid because b is not a constant expression. In particular, it's not a constant list element.
The const A([b]) is invalid because [b] is not a valid constant expression. It can be invalid for two reasons:

  • Because [...] is intended to be constant, and b is not a valid constant list element, or
  • Because [b] is not constant at all (it's a valid non-constant list expression where a constant expression is needed).

The latter is a little weird, because we'd assume that [b] in a const context will automatically be constant, but we also require it to be valid, and it isn't.
It does seems from the error that it's the latter that triggers the error.

For [if (true) b] and [if (false) b], an expression of the form [if (c) b] is a valid constant if c is true and b is a valid constant expression, or if c is false and b is a potentially constant expression (but possibly not valid constant expression).

Here b is neither. In the if (false) case, that makes if (false) b into an invalid constant expression in an element position.
In if (true), it the detected error is that b (which is used here) is not constant, but it's not used directly as a list element (well, it is, but not just).

Basically, there are multiple ways each example could be deemed invalid, and the error depends on which one happens to be detected first.

(Or maybe, as you say, some errors are just more up-to-date than the others, which will follow soon enough.)

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.