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

Show warning when DU is accessed without type but RequiredQualifiedAccess was set #103

Closed
wants to merge 4 commits into from

Conversation

forki
Copy link
Contributor

@forki forki commented Jan 25, 2015

This fixes #95 by showing a deprecated warning.

image

@@ -1526,13 +1526,16 @@ type RecdFieldInfo =
/// Describes an F# use of a union case
[<NoComparison; NoEquality>]
type UnionCaseInfo =
| UnionCaseInfo of TypeInst * Tast.UnionCaseRef
| UnionCaseInfo of TypeInst * Tast.UnionCaseRef * bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change the PR to add the flag as Item.UnionCase(ucref,flag) rather than to UnionCaseInfo please? This is because the flag is really a transient thing related to name resolution, whereas the UnionCaseInfo is like a reflection-handle to the union case, representing the logical item.

@dsyme
Copy link
Contributor

dsyme commented Jan 25, 2015

Cool work, you're basically there.

@forki
Copy link
Contributor Author

forki commented Jan 26, 2015

done

@forki
Copy link
Contributor Author

forki commented Jan 26, 2015

Fun fact: even the compiler itself had such an invalid case. see 416ea92

@isaacabraham
Copy link
Contributor

@forki Ok my head just imploded.

@forki
Copy link
Contributor Author

forki commented Jan 26, 2015

tumblr_inline_nczxolfvuz1raprkq

| Item.UnionCase ucinfo ->
| Item.UnionCase(ucinfo,showDeprecated) ->
if showDeprecated then
let message = sprintf "The union type for union case '%s' was defined with the RequireQualifiedAccessAttribute. Include the name of the union type ('%s') in the name you are using.'" ucinfo.Name ucinfo.Tycon.DisplayName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to go in FSComp.txt (so it can be localized by Microsoft into Japanese etc.) Look around tc.fs and elsewhere for examples.

@dsyme
Copy link
Contributor

dsyme commented Jan 26, 2015

This is good. Just two remaining things

  • Put the error message in FSComp.txt, as mentioned above
  • Add test cases.

It's easiest to add negative tests at the end of https://github.com/Microsoft/visualfsharp/blob/fsharp4/tests/fsharp/typecheck/sigs/neg90.fs (or one of the other exiting neg* files). Then update the baseline by running the typecheck/sigs tests, letting them fail, checking the error messages look right, and then copying the contents of neg90.err to neg90.bsl (we generally don't mind if each neg* test covers 3-5 different aspects of name resolution of type checking).

@forki
Copy link
Contributor Author

forki commented Jan 26, 2015

done.

@dsyme
Copy link
Contributor

dsyme commented Jan 26, 2015

Fabulous. This is ready to go as far as I can see.

@forki
Copy link
Contributor Author

forki commented Jan 26, 2015

I will submit my solution to RecordField bug in a separate PR.

@latkin
Copy link
Contributor

latkin commented Jan 26, 2015

Looks good to me, nice work Steffen.

Side conversation -- what is the recommended formatting for DUs across the compiler/runtime: SomeCase(no,spaces,_,btw,args) or SomeCase(with, spaces, _, btw, args)? It appears to be a mishmash at the moment. Personally I prefer with spaces, and FWIW that's how the Power Tools formatting does it.

@forki
Copy link
Contributor Author

forki commented Jan 26, 2015

I know it's inconsistent, but I tried to match the style around the modified lines. At least I tried ;-)

@latkin
Copy link
Contributor

latkin commented Jan 27, 2015

vsintegration side of the repo does not build with this, there are a few spots that are now being flagged 😆

@@ -4,3 +4,5 @@ neg90.fs(4,9,4,12): typecheck error FS0001: A generic construct requires that th
neg90.fs(7,22,7,25): typecheck error FS0039: The type 'foo' is not defined

neg90.fs(7,22,7,25): typecheck error FS0039: The type 'foo' is not defined

neg90.fs(16,9,16,21): typecheck error FS0035: This construct is deprecated: The union type for union case 'Member' was definded with the RequireQualifiedAccessAttribute. Include the name of the union type ('DU') in the name you are using.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo - definded -> defined

@latkin latkin closed this in c52b4dd Jan 27, 2015
@latkin latkin added the fixed label Jan 27, 2015
@dsyme
Copy link
Contributor

dsyme commented Jan 27, 2015

@latkin - Definitely use a space after a comma. At some point we should normalize the entire F# codebase to always have a space after a comma.

@forki forki deleted the rqa branch September 2, 2016 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants