Skip to content

Commit 2e3363f

Browse files
Several fixes
1 parent cfd55e1 commit 2e3363f

File tree

8 files changed

+42
-26
lines changed

8 files changed

+42
-26
lines changed

RELEASE_NOTES_COMPILER.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
### 0.7.15
2+
3+
* Issue warning when calling `typeof` on a generic parameter
4+
* Use absolute paths for assembly references in `node_modules`
5+
16
### 0.7.14
27

38
* Use "umd" distribution of fable-core and other libs when compiling for umd modules
49
* Fix #569: Types with circular dependencies
510

611
### 0.7.12
712

8-
* Fix #568: Types with `StructAttribute`
13+
* Fix #568: Types with `StructAttribute` (compiled as records)
914
* Better checking when calling functions with `PassGenericsAttribute`
1015

1116
### 0.7.11

src/fable/Fable.Client.Node/AssemblyInfo.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
namespace System
33
open System.Reflection
44

5-
[<assembly: AssemblyVersionAttribute("0.7.10")>]
6-
[<assembly: AssemblyMetadataAttribute("fableCoreVersion","0.7.9")>]
5+
[<assembly: AssemblyVersionAttribute("0.7.15")>]
6+
[<assembly: AssemblyMetadataAttribute("fableCoreVersion","0.7.11")>]
77
do ()
88

99
module internal AssemblyVersionInformation =
10-
let [<Literal>] AssemblyVersion = "0.7.10"
11-
let [<Literal>] AssemblyMetadata_fableCoreVersion = "0.7.9"
10+
let [<Literal>] AssemblyVersion = "0.7.15"
11+
let [<Literal>] AssemblyMetadata_fableCoreVersion = "0.7.11"

src/fable/Fable.Compiler/AssemblyInfo.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
namespace System
33
open System.Reflection
44

5-
[<assembly: AssemblyVersionAttribute("0.7.10")>]
5+
[<assembly: AssemblyVersionAttribute("0.7.15")>]
66
do ()
77

88
module internal AssemblyVersionInformation =
9-
let [<Literal>] AssemblyVersion = "0.7.10"
9+
let [<Literal>] AssemblyVersion = "0.7.15"

src/fable/Fable.Compiler/FSharp2Fable.fs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -776,11 +776,13 @@ let private processMemberDecls (com: IFableCompiler) ctx (fableEnt: Fable.Entity
776776
("FSharpUnion"::fableEnt.Interfaces) (Some cases) None
777777
if needsEqImpl then yield makeUnionEqualMethod fableType
778778
if needsCompImpl then yield makeUnionCompareMethod fableType ]
779-
// TODO: Use specific interface for FSharpException?
780779
| Fable.Record fields
781780
| Fable.Exception fields ->
782781
let isEx = match fableEnt.Kind with Fable.Exception _ -> true | _ -> false
783-
[ yield makeRecordCons isEx fields
782+
// Structs are considered equivalent to records but
783+
// some already include a constructor (see #569)
784+
[ if fableEnt.Members |> Seq.exists (fun m -> m.Kind = Fable.Constructor) |> not
785+
then yield makeRecordCons isEx fields
784786
yield makeReflectionMeth fableEnt false fableEnt.FullName
785787
("FSharpRecord"::fableEnt.Interfaces) None (Some fields)
786788
if needsEqImpl then yield makeRecordEqualMethod fableType
@@ -1149,25 +1151,29 @@ let private getProjectMaps (com: ICompiler) (parsedProj: FSharpCheckProjectResul
11491151
try
11501152
let asmName = Path.GetFileNameWithoutExtension(asmPath)
11511153
let resolve =
1154+
// TODO: Use a case insensitive search?
11521155
match Map.tryFind asmName com.Options.refs with
11531156
| Some baseDir when baseDir.StartsWith(".") ->
1154-
let baseDir = Path.GetFullPath(baseDir)
1155-
fun path -> Path.GetFullPath(combine baseDir path)
1157+
Path.GetFullPath(baseDir)
11561158
| Some baseDir ->
11571159
// The triple slash is just a mark to indicate
11581160
// the import must NOT be resolved with a relative path
1159-
fun path -> "///" + combine baseDir path
1161+
"///" + baseDir
11601162
| None ->
11611163
let baseDir =
1162-
let asmDir = Path.GetDirectoryName(asmPath)
1164+
let asmDir = Path.GetDirectoryName(Path.GetFullPath(asmPath))
11631165
// If we're compiling to a non-ES2015 module check if the referenced
11641166
// library includes a UMD distribution
11651167
if Naming.umdModules.Contains com.Options.moduleSystem
11661168
then
1167-
let umdDir = Path.GetFullPath(Path.Combine(asmDir, "umd"))
1169+
let umdDir = Path.Combine(asmDir, "umd")
11681170
if Directory.Exists(umdDir) then umdDir else asmDir
11691171
else asmDir
1170-
fun path -> Path.GetFullPath(combine baseDir path)
1172+
// If the assembly is an npm package, use an absolute reference
1173+
let i = baseDir.IndexOf("node_modules/")
1174+
if i > -1 then "///" + baseDir.Substring(i + 13) else baseDir
1175+
|> fun baseDir ->
1176+
fun path -> combine baseDir path
11711177
let fableMap =
11721178
let json = File.ReadAllText(mapPath)
11731179
Newtonsoft.Json.JsonConvert.DeserializeObject<Fable.FableMap>(json).files

src/fable/Fable.Compiler/Replacements.fs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,18 @@ module private AstPass =
569569
Fable.Throw (newError None Fable.Any args, typ, r) |> Some
570570
// Type ref
571571
| "typeOf" | "typeDefOf" ->
572-
let genInfo = {
573-
makeGeneric = info.methodName = "typeOf"
574-
genericAvailability = info.genericAvailability
575-
}
576-
info.methodTypeArgs.Head
577-
|> makeTypeRef genInfo |> Some
572+
let genInfo =
573+
{ makeGeneric = info.methodName = "typeOf"
574+
; genericAvailability = info.genericAvailability }
575+
match info.methodTypeArgs with
576+
| [Fable.GenericParam _ as t] when not info.genericAvailability ->
577+
"`typeof` is being called on a generic parameter, "
578+
+ "consider inlining the method (for `internal` members) "
579+
+ "or using `PassGenericsAttribute`."
580+
|> addWarning com info
581+
makeTypeRef genInfo t |> Some
582+
| [t] -> makeTypeRef genInfo t |> Some
583+
| _ -> None
578584
// Concatenates two lists
579585
| "op_Append" ->
580586
CoreLibCall("List", Some "append", false, args)
@@ -1430,7 +1436,7 @@ module private AstPass =
14301436
let types com (info: Fable.ApplyInfo) =
14311437
let str x = Fable.Value(Fable.StringConst x)
14321438
match info.callee with
1433-
| Some(Fable.Value(Fable.TypeRef(ent,[]))) ->
1439+
| Some(Fable.Value(Fable.TypeRef(ent,_))) ->
14341440
match info.methodName with
14351441
| "namespace" -> str ent.Namespace |> Some
14361442
| "fullName" -> str ent.FullName |> Some

src/fable/Fable.Core/AST/AST.Fable.Util.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ type GenericInfo = {
129129
}
130130

131131
let rec makeTypeRef (genInfo: GenericInfo) typ =
132-
let (|TryDecorator|_|) dec (ent: Fable.Entity) = ent.TryGetDecorator dec
133132
let str s = Wrapped(Value(StringConst s), MetaType)
134133
match typ with
135134
| Boolean -> str "boolean"

src/fable/Fable.Core/AssemblyInfo.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
namespace System
33
open System.Reflection
44

5-
[<assembly: AssemblyVersionAttribute("0.7.10")>]
5+
[<assembly: AssemblyVersionAttribute("0.7.11")>]
66
do ()
77

88
module internal AssemblyVersionInformation =
9-
let [<Literal>] AssemblyVersion = "0.7.10"
9+
let [<Literal>] AssemblyVersion = "0.7.11"

src/tests/Main/TypeTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ type ValueType<'T> =
474474
member x.Value = foo
475475

476476
[<Struct>]
477-
type ValueType2<'T>(i: int, j: int) =
477+
type ValueType2(i: int, j: int) =
478478
member x.Value = i + j
479479

480480
type Point2D =

0 commit comments

Comments
 (0)