Variables should not require declaration

Bug #483082 reported by Matt Giuca
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mars
Fix Released
High
Matt Giuca

Bug Description

Mars has always required variables declared with the "var" keyword.

This is annoying. Mars (like Python) should treat any variable assigned anywhere in the body of a function as local, and infer the type from the assignment statement. (This is already done in interactive mode, and for variables created in switch statements).

Tags: language types

Related branches

Matt Giuca (mgiuca)
Changed in mars:
milestone: none → 0.3
Matt Giuca (mgiuca)
Changed in mars:
status: New → Triaged
Revision history for this message
Matt Giuca (mgiuca) wrote :

This should be fixed automatically by bug #513633. Since assignments would be treated as pattern bindings, the same declaration-free semantics of switch statements would be used by assignments. Therefore, it would not be necessary to declare variables at all in Mars.

HOWEVER, note the last paragraph of this bug report still holds -- need to fix the fact that if a local variable is bound by a pattern (assignment or switch), it can't be treated as a global beforehand, even if only being read.

Revision history for this message
Matt Giuca (mgiuca) wrote :

The second part of this bug, making sure that implicitly-declared locals are scoped to the whole function, is now a separate bug #513638.

Fix bug #513633 and bug #513638, and you should have full support for implicitly-declared variables.

Note that the "var" keyword should not be removed. I'd like to keep it around, so it is possible to *explicitly* declare a variable, if desired.

Matt Giuca (mgiuca)
description: updated
description: updated
Revision history for this message
Matt Giuca (mgiuca) wrote :

I no longer consider this to be "Blocked by bug #513633 and bug #513638." While allowing declaration-free variables will expose those two bugs, they are already exposed via pattern bindings. So I'll allow this (further exposing those two bugs) and fix them afterwards.

(In a branch -- newtypes.)

Now high priority.

Changed in mars:
importance: Wishlist → High
description: updated
Revision history for this message
Matt Giuca (mgiuca) wrote :

Fixed in newtypes branch, r1013.

Changed in mars:
status: Triaged → Fix Committed
Revision history for this message
Matt Giuca (mgiuca) wrote :

Merged to trunk, r1030.

Matt Giuca (mgiuca)
Changed in mars:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.