Skip to content
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

Cannot specify Literal attribute in signature file #7897

Closed
auduchinok opened this issue Nov 22, 2019 · 8 comments
Closed

Cannot specify Literal attribute in signature file #7897

auduchinok opened this issue Nov 22, 2019 · 8 comments
Assignees
Labels
Milestone

Comments

@auduchinok
Copy link
Member

range.fs(203, 17): [FS0034] Module 'FSharp.Compiler.Range' contains�    val UnknownFileName : string    �but its signature specifies�    val UnknownFileName : string    �The literal constant values and/or attributes differ

Related StackOverflow topic:
https://stackoverflow.com/questions/48212721/unable-to-use-the-literal-attribute-in-an-f-signature-file-fsi

@auduchinok
Copy link
Member Author

Please also note the corrupted line separators, previously reported in #4516.

@TIHan
Copy link
Contributor

TIHan commented Nov 22, 2019

I've known about this for a while but I never created an issue, which I should have. Thank you a lot for making the issue.

This is actually very annoying because there are a lot of places where [<Literal>] really should be used. I'm just going to go ahead and fix this.

@TIHan TIHan self-assigned this Nov 22, 2019
@TIHan
Copy link
Contributor

TIHan commented Nov 22, 2019

After looking at the parser, the issue might be related to light status. Funny enough, if I turn light syntax "off", it will work:

module Thingo

#light "off"

[<Literal>]
val hello : string = "world"

val x : int

@abelbraaksma
Copy link
Contributor

From the referenced SO issue, I noticed that auto-generation will trigger 'heavy' syntax. However, the OP didn't use it with light "off", and nobody suggested it (I never even considered it).

Heavy syntax, but not selected:

Screenshot_20191123-021137_Stack Exchange

You're basically saying 'it works', but not the way you'd expect.

@TIHan
Copy link
Contributor

TIHan commented Nov 23, 2019

The generation is incorrect, that's a bug as well. The signature should be:

[<Literal>]
val id : string = "some string`

@abelbraaksma
Copy link
Contributor

If you then use the generator-apporach, you'd end up with two places where the literal is defined and assigned a value. That looks like a problem waiting to happen, or will the compiler know & check that the constants are equal?

@TIHan
Copy link
Contributor

TIHan commented Nov 23, 2019

It's part of the design and compiler will know about it; if the values are different, the compiler will error.

From FSharpSpec 4.1 - 11.2.1 Signature Conformance for Functions and Values

If either the signature or the implementation has the [<Literal>] attribute, both must have this
attribute. Furthermore, the declared literal values must be identical.

@cartermp cartermp added this to the Backlog milestone Nov 23, 2019
@abelbraaksma
Copy link
Contributor

Fixed in #7901, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants