Skip to content

Commit

Permalink
handle AllowNullLiteral(false) correctly, fixes #383
Browse files Browse the repository at this point in the history
closes #390

commit a9c9d60
Author: Max Malook <community@malook.de>
Date:   Wed Apr 29 04:43:26 2015 +0200

    handle AllowNullLiteral(false) correctly, fixes #383

commit 574b9b3
Author: Max Malook <community@malook.de>
Date:   Wed Apr 29 01:34:54 2015 +0200

    add tests to verify correct usage of new argument on AllowNullLiteralAttribute
  • Loading branch information
mexx authored and latkin committed Apr 30, 2015
1 parent 37aa969 commit 8b249d8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fsharp/tc.fs
Expand Up @@ -13982,7 +13982,7 @@ module EstablishTypeDefinitionCores = begin
let hasCLIMutable = HasFSharpAttribute cenv.g cenv.g.attrib_CLIMutableAttribute attrs

let hasStructLayoutAttr = HasFSharpAttribute cenv.g cenv.g.attrib_StructLayoutAttribute attrs
let hasAllowNullLiteralAttr = HasFSharpAttribute cenv.g cenv.g.attrib_AllowNullLiteralAttribute attrs
let hasAllowNullLiteralAttr = TryFindFSharpBoolAttribute cenv.g cenv.g.attrib_AllowNullLiteralAttribute attrs = Some(true)

if hasAbstractAttr then
tycon.TypeContents.tcaug_abstract <- true
Expand Down
2 changes: 2 additions & 0 deletions tests/fsharp/typecheck/sigs/neg16.bsl
Expand Up @@ -88,3 +88,5 @@ neg16.fs(110,16,110,20): typecheck error FS0879: Volatile fields must be marked
neg16.fs(113,9,113,11): typecheck error FS0879: Volatile fields must be marked 'mutable' and cannot be thread-static

neg16.fs(116,9,116,13): typecheck error FS0879: Volatile fields must be marked 'mutable' and cannot be thread-static

neg16.fs(130,10,130,11): typecheck error FS0935: Types with the 'AllowNullLiteral' attribute may only inherit from or implement types which also allow the use of the null literal
8 changes: 8 additions & 0 deletions tests/fsharp/typecheck/sigs/neg16.fs
Expand Up @@ -122,3 +122,11 @@ module VolatileFieldSanityChecks = begin

end

module AllowNullLiteralWithArgumentTest = begin

type A() = class end

[<AllowNullLiteral(true)>] // expect an error here
type B() = inherit A()

end
7 changes: 7 additions & 0 deletions tests/fsharp/typecheck/sigs/pos16.fs
Expand Up @@ -46,3 +46,10 @@ module UnitOfMeasurePrintfPositiveTests =
let _ = sprintf "%g" 1.0M<metre>
let _ = sprintf "%g" 1.0M<m>
let _ = sprintf "%g" 1.0M<m/s>

module AllowNullLiteralWithArgumentTest =

type A() = class end

[<AllowNullLiteral(false)>]
type B() = inherit A()

0 comments on commit 8b249d8

Please sign in to comment.