From 278c300dcddc7af7af1815c9770cbceceac0ae78 Mon Sep 17 00:00:00 2001 From: Dimi Racordon Date: Thu, 22 Aug 2024 16:18:49 +0200 Subject: [PATCH 1/3] Keep track of generic arguments passed to synthetic generic functions --- Sources/FrontEnd/TypeChecking/TypeChecker.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/FrontEnd/TypeChecking/TypeChecker.swift b/Sources/FrontEnd/TypeChecking/TypeChecker.swift index b59f90ff0..71454aa5d 100644 --- a/Sources/FrontEnd/TypeChecking/TypeChecker.swift +++ b/Sources/FrontEnd/TypeChecking/TypeChecker.swift @@ -4434,9 +4434,16 @@ struct TypeChecker { // `X` from the resolution of the qualification and `Y` from the resolution of the candidate. entityType = specialize(entityType, for: specialization, in: scopeOfUse) + // If `d` is a trait requirement, we have to remember the generic arguments that are part of + // its qualification in case its implementation is synthesized. Otherwise, we should only + // remember arguments to parameters that are in `d`'s scope. var capturedArguments = GenericArguments.empty - for p in capturedGenericParameter(of: d) { - capturedArguments[p] = specialization[p] + if program.isRequirement(d) { + capturedArguments = specialization + } else { + for p in capturedGenericParameter(of: d) { + capturedArguments[p] = specialization[p] + } } return (entityType, capturedArguments, isConstructor) From ea736cae89f8a0c67c38e0c70080aa5d733e83ba Mon Sep 17 00:00:00 2001 From: Dimi Racordon Date: Thu, 22 Aug 2024 16:19:29 +0200 Subject: [PATCH 2/3] Remove needless custom implementation of `None.infix==` --- StandardLibrary/Sources/Core/Optional.hylo | 5 ----- 1 file changed, 5 deletions(-) diff --git a/StandardLibrary/Sources/Core/Optional.hylo b/StandardLibrary/Sources/Core/Optional.hylo index ced3b2c4f..1d9e04b0a 100644 --- a/StandardLibrary/Sources/Core/Optional.hylo +++ b/StandardLibrary/Sources/Core/Optional.hylo @@ -9,11 +9,6 @@ public type None: Regular { /// Creates a value denoting the absence of an instance of `T`. public memberwise init - // TODO: Remove when #1078 is implemented. - public fun infix==(_ other: Self) -> Bool { - true - } - } public extension Optional { From 9fdd9994fc22fe45867c8683f7668205c02c82d4 Mon Sep 17 00:00:00 2001 From: Dimi Racordon Date: Thu, 22 Aug 2024 16:20:43 +0200 Subject: [PATCH 3/3] Test equality between instances of 'None' --- Tests/LibraryTests/TestCases/OptionalTests.hylo | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/LibraryTests/TestCases/OptionalTests.hylo b/Tests/LibraryTests/TestCases/OptionalTests.hylo index 22d1d8801..c7cddb347 100644 --- a/Tests/LibraryTests/TestCases/OptionalTests.hylo +++ b/Tests/LibraryTests/TestCases/OptionalTests.hylo @@ -1,6 +1,8 @@ //- compileAndRun expecting: .success public fun main() { + precondition(None() == None()) + var x = 42 as Optional let y = if let i: Int = x { i.copy() } else { 0 } precondition(y == 42)