-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix indentation ambiguities when attributes are involved #514
Comments
actually it's already possible let [<Literal>] First = 1
let [<Literal>] Second = 2 |
this code is much more readable and elegant [<Literal>] let First = 1
[<Literal>] let Second = 2 I support abelbraaksma's suggestion. |
@cloudRoutine, I know that that's an alternative syntax, but that doesn't remove the ambiguity in the current indentation rules if you don't abide by that syntax, and as @AlOdeychuk mentions, orthogonality in syntax is a good thing, and indeed more readable. If the ground rule is that the |
@abelbraaksma this is all i was responding to I agree regarding the indentation rule, I've made the same point regarding generic signatures |
@dsyme, I think this could work if the offset is not taken into account when inside a an attribute. In other words, [<SomeAttribute>] let x =
12 + 30 Or: [<SomeAttribute>] let x = 12 + 30
[<SomeAttribute>] let y = 12 + 30 Or [<SomeAttribute>] let x = 12 + 30
let y = 12 + 30 would then all be valid. I'd be interested in resolving this, but then this lang-suggestion should first get some "approved-in-principle" or the like from you or someone else at the team (@KevinRansom, @cartermp perhaps?). I am not sure it requires a full RFC, as I think the spec is currently fuzzy about the position-count in these respects, but I have no problem writing one. Perhaps fixing this could also help me get some pointers about fixing the problems with static type constraints (this too requires far right-indent, several issues have been reported about it). |
IMO this feels more like a bug than anything else, though @dsyme has the final word here. |
@cartermp, yes, and it was first reported as a bug ;). In the OP I apparently wrote (but then forgot about dotnet/fsharp#1649):
But I think this summarizes the reason why @dsyme wanted to see this done through an RFC:
|
@cartermp It's certainly a glitch/bug. That said I'm always concerned about the potential for fixes to destabilize things in the parsing area, so we have to be very careful about a change. It's also possible that the change would be to deprecate existing constructs (e.g. inline access) if a safe change to enable orthogonal behaviour is not easy |
@dsyme, talking about consistency, it currently works properly for types, but not (yet) for let-bindings. This suggests to me that the necessary machinery is already available in the parser, it just doesn't currently consider attributes, whereas it does consider them for types: [<AutoOpen>]
module M =
[<AbstractClass>] type C() = class end
[<AbstractClass>] type D() = class end // no indentation warning
[<AbstractClass>] type E() = class end // no indentation warning
[<Literal>] let X = 3
[<Literal>] let Y = 3 // indentation warning
[<Literal>] let Z = 3 // indentation warning Using an attribute with |
Looking through the examples above, they all involve one-line I don't think we need to specifically do anything here. |
I propose we fix the issues that causes incorrect throwing of FS0058 warning on incorrect indentation, and that we accept the left-most point of a line as its indentation start-point.
Currently, if you write
[<Literal>] let x = 12
, the warning is raised on the the position after[<Literal>]
, placing several literals underneath each other is therefore impossible. However, the warning itself points to the wrong position, you can indent the next line by one column to remove the warning.For attributes that involve parameters, the FS0058 error is raised on the wrong position entirely.
Let bindings repro
This throws FS0058 on "let"
Minimal indentation to prevent warning (which oddly suggests it is an inner let-binding, but this is not how it gets compiled)
Let bindings with parens repro
Minimal indentation to prevent both warnings (to prevent only the second, one space is enough):
Pros and Cons
The advantages of letting the indentation position start at the
[
of the attribute is that your code becomes more legible. It also removes the ambiguity that it gets the position wrong in the warning itself.All in all it simply creates a more orthogonal coding experience: the indentation rule is that the next line must start on the same position as the previous line (or indented if it is part of the scope of the previous line).
I don't see disadvantages at the moment, but feel free to comment on it if there are. Since it fixes an error scenario, there are no backward incompatibility issues.
Extra information
I have to admit that I don't know the complexity of fixing this is.
I raised this originally as a bug (and I think that in part it still is a bug) here: dotnet/fsharp#1649
Related Suggestions
Affidavit
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: