Files
swift-mirror/validation-test/compiler_crashers_fixed/28369-swift-decl-walk.swift
Doug Gregor aa3d024f8d [Type checker] Eliminate reuse of contextual archetypes in nested generics.
Prior to this change, nested generics always reused the archetypes of
either enclosing contexts. For example, given:

  struct X<T> {
    func f<U>(_: U) { }
  }

The generic environment for X.f(_:) would use the same archetype for T
as the generic environment X. This reuse allowed some sloppiness
within the implementation---one did not necessarily have to remember
to substitute entities that came from an immediate outer context---but
caused an annoying limitation that nested generics could not add any
constraints to an archetype that came from an outer scope. Worse, the
compiler would not always diagnose this as an error, leading to
constraints being silently dropped, as in the example from the
referenced radar (see the change to
test/Generics/associated_types.swift).

Now, build a fresh generic environment for each context that
introduces new generic parameters, with archetypes that are completely
separate from the archetypes of enclosing contexts.

Fixes rdar://problem/29207581.
2016-12-07 08:10:12 -08:00

18 lines
553 B
Swift

// This source file is part of the Swift.org open source project
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
// Credits: https://twitter.com/kiliankoe/status/752090953977036800
// RUN: %target-swift-frontend %s -typecheck
protocol P {
}
struct A<T> {
func a<B where T: P>(b: B) -> B {
return b
}
}