Bug 16132 – std.variant.VariantN does not work with a class that inherits from a template instantiation

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-06-06T14:37:41Z
Last change time
2019-08-02T02:47:23Z
Keywords
pull
Assigned to
No Owner
Creator
gmanev72

Comments

Comment #0 by gmanev72 — 2016-06-06T14:37:41Z
The following code does not compile. The error is: ../src/phobos/std/variant.d(546,9): Error: static assert "Cannot store a C in a VariantN!(8LU, C)" interface I(T) { } class C : I!int { } auto c = new C; Algebraic!C a = c; Most probably the cause is how AllowedTypes is determined. It uses std.typecons.ReplaceType to replace This with VariantN. Here is a short repro of the cause: import std.typecons; static assert(is(ReplaceType!(int, string, C) == I!string)); So the type C is replaced with I!int in VariantN.AllowedTypes.
Comment #1 by dlang-bot — 2019-07-31T23:41:01Z
@pbackus created dlang/phobos pull request #7121 "Fix issues 19696, 19697, 16132 - ReplaceType bugs" fixing this issue: - Fix issues 19696, 19697, 16132 - ReplaceType bugs ReplaceType no longer gives incorrect results for types that can be implicitly converted to a templated type, either via inheritance (19697, 16132) or alias this (19696). https://github.com/dlang/phobos/pull/7121
Comment #2 by dlang-bot — 2019-08-02T02:47:23Z
dlang/phobos pull request #7121 "Fix issues 19696, 19697, 16132 - ReplaceType bugs" was merged into stable: - e7d6e9ff508fee42eea9986c0fb59bd3546b862f by Paul Backus: Fix issues 19696, 19697, 16132 - ReplaceType bugs ReplaceType no longer gives incorrect results for types that can be implicitly converted to a templated type, either via inheritance (19697, 16132) or alias this (19696). https://github.com/dlang/phobos/pull/7121