Merge branch 'main' into i4416

Signed-off-by: Ayaz <20735482+ayazhafiz@users.noreply.github.com>
This commit is contained in:
Ayaz 2022-11-17 09:07:00 -06:00 committed by GitHub
commit a74d7e14b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 102 additions and 24 deletions

View file

@ -2960,12 +2960,13 @@ fn type_to_variable<'a>(
_ => {
let abilities_slice =
SubsSlice::extend_new(&mut subs.symbol_names, abilities.sorted_iter().copied());
let flex_ability = subs.fresh(Descriptor {
content: Content::FlexAbleVar(None, abilities_slice),
let flex_ability = register(
subs,
rank,
mark: Mark::NONE,
copy: OptVariable::NONE,
});
pools,
Content::FlexAbleVar(None, abilities_slice),
);
let category = Category::OpaqueArg;
match unify(

View file

@ -8236,4 +8236,26 @@ mod solve_expr {
@"Hash#Hash.hash(1) : a, I64 -[[Hash.hashI64(12)]]-> a | a has Hasher"
)
}
#[test]
fn generalize_inferred_opaque_variable_bound_to_ability_issue_4408() {
infer_eq_without_problem(
indoc!(
r#"
app "test" provides [top] to "./platform"
MDict u := (List u) | u has Eq
bot : MDict k -> MDict k
bot = \@MDict data ->
when {} is
{} -> @MDict data
top : MDict v -> MDict v
top = \x -> bot x
"#
),
"MDict v -> MDict v | v has Eq",
);
}
}

View file

@ -798,8 +798,10 @@ fn subs_fmt_content(this: &Content, subs: &Subs, f: &mut fmt::Formatter) -> fmt:
};
write!(f, "FlexAble({}, {:?})", name, subs.get_subs_slice(*symbols))
}
Content::RigidVar(name) => write!(f, "Rigid({:?})", name),
Content::RigidAbleVar(name, symbol) => write!(f, "RigidAble({:?}, {:?})", name, symbol),
Content::RigidVar(name) => write!(f, "Rigid({})", subs[*name].as_str()),
Content::RigidAbleVar(name, symbol) => {
write!(f, "RigidAble({}, {:?})", subs[*name].as_str(), symbol)
}
Content::RecursionVar {
structure,
opt_name,

View file

@ -468,6 +468,12 @@ pre {
line-height: 15px;
}
.builtins-tip {
padding: 1em;
font-style: italic;
line-height: 1.3em;
}
@media (prefers-color-scheme: dark) {
:root {
--body-bg-color: var(--purple-8);

View file

@ -182,7 +182,8 @@ mod test {
// changes between test runs
let p = actual.bytes().position(|c| c == b'\n').unwrap();
let (_, x) = actual.split_at(p);
let x = x.trim_start();
let x = x.trim();
let expected = expected.trim_end();
if x != expected {
println!("{}", x);
@ -856,14 +857,14 @@ mod test {
First Str U8,
Next (List { item: Str, rest: NonEmpty }),
]
expect
nonEmpty =
a = "abcdefgh"
b = @NonEmpty (First "ijkl" 67u8)
c = Next [{ item: a, rest: b }]
@NonEmpty c
when nonEmpty is
_ -> Bool.false
"#
@ -871,7 +872,7 @@ mod test {
indoc!(
r#"
This expectation failed:
8> expect
9> nonEmpty =
10> a = "abcdefgh"
@ -881,9 +882,9 @@ mod test {
14>
15> when nonEmpty is
16> _ -> Bool.false
When it failed, these variables had these values:
nonEmpty : NonEmpty
nonEmpty = @NonEmpty (Next [{ item: "abcdefgh", rest: @NonEmpty (First "ijkl" 67) }])
"#

View file

@ -1017,9 +1017,20 @@ pub fn can_problem<'b>(
}
Problem::UnnecessaryOutputWildcard { region } => {
doc = alloc.stack([
alloc.reflow("I see you annotated a wildcard in a place where it's not needed:"),
alloc.concat([
alloc.reflow("This type annotation has a wildcard type variable ("),
alloc.keyword("*"),
alloc.reflow(") that isn't needed."),
]),
alloc.region(lines.convert_region(region)),
alloc.reflow("Tag unions that are constants, or the return values of functions, are always inferred to be open by default! You can remove this annotation safely."),
alloc.concat([
alloc.reflow("Annotations for tag unions which are constants, or which are returned from functions, work the same way with or without a "),
alloc.keyword("*"),
alloc.reflow(" at the end. (The "),
alloc.keyword("*"),
alloc.reflow(" means something different when the tag union is an argument to a function, though!)"),
]),
alloc.reflow("You can safely remove this to make the code more concise without changing what it means."),
]);
title = "UNNECESSARY WILDCARD".to_string();
severity = Severity::Warning;

View file

@ -94,11 +94,13 @@ impl<'a> Renderer<'a> {
self.alloc
.text("When it failed, these variables had these values:"),
self.alloc.stack(it),
self.alloc.text(""), // Blank line at the end
])
} else {
self.alloc.stack([
self.alloc.text("This expectation failed:"),
self.alloc.region(line_col_region),
self.alloc.text(""), // Blank line at the end
])
}
}

View file

@ -275,7 +275,7 @@ pub const ANSI_STYLE_CODES: StyleCodes = StyleCodes {
macro_rules! html_color {
($name: expr) => {
concat!("<span style='color: ", $name, "'>")
concat!("<span class='color-", $name, "'>")
};
}
@ -287,8 +287,8 @@ pub const HTML_STYLE_CODES: StyleCodes = StyleCodes {
magenta: html_color!("magenta"),
cyan: html_color!("cyan"),
white: html_color!("white"),
bold: "<span style='font-weight: bold'>",
underline: "<span style='text-decoration: underline'>",
bold: "<span class='bold'>",
underline: "<span class='underline'>",
reset: "</span>",
color_reset: "</span>",
};

View file

@ -11772,14 +11772,19 @@ All branches in an `if` must have the same type!
@r###"
UNNECESSARY WILDCARD /code/proj/Main.roc
I see you annotated a wildcard in a place where it's not needed:
This type annotation has a wildcard type variable (`*`) that isn't
needed.
4 f : {} -> [A, B]*
^
Tag unions that are constants, or the return values of functions, are
always inferred to be open by default! You can remove this annotation
safely.
Annotations for tag unions which are constants, or which are returned
from functions, work the same way with or without a `*` at the end. (The
`*` means something different when the tag union is an argument to a
function, though!)
You can safely remove this to make the code more concise without
changing what it means.
"###
);

View file

@ -56,7 +56,7 @@ mv generated-docs/*.* www/build # move all the .js, .css, etc. files to build/
mv generated-docs/ www/build/builtins # move all the folders to build/builtins/
# Manually add this tip to all the builtin docs.
find www/build/builtins -type f -name 'index.html' -exec sed -i 's!</nav>!<div style="padding: 1em;font-style: italic;line-height: 1.3em;"><strong>Tip:</strong> <a href="/different-names">Some names</a> differ from other languages.</div></nav>!' {} \;
find www/build/builtins -type f -name 'index.html' -exec sed -i 's!</nav>!<div class="builtins-tip"><b>Tip:</b> <a href="/different-names">Some names</a> differ from other languages.</div></nav>!' {} \;
echo 'Generating CLI example platform docs...'
# Change ROC_DOCS_ROOT_DIR=builtins so that links will be generated relative to

View file

@ -1,4 +1,4 @@
<svg viewBox="0 0 52 53" xmlns="http://www.w3.org/2000/svg">
<style>polygon {fill: #5c0bff;}@media (prefers-color-scheme: dark) {polygon {fill: #7733ff;}} </style>
<style>polygon {fill: #7d59dd;}@media (prefers-color-scheme: dark) {polygon {fill: #9c7bea;}}</style>
<polygon points="0,0 23.8834,3.21052 37.2438,19.0101 45.9665,16.6324 50.5,22 45,22 44.0315,26.3689 26.4673,39.3424 27.4527,45.2132 17.655,53 23.6751,22.7086"/>
</svg>

Before

Width:  |  Height:  |  Size: 335 B

After

Width:  |  Height:  |  Size: 334 B

Before After
Before After

View file

@ -75,3 +75,31 @@ section.source textarea {
padding: 8px;
margin-bottom: 16px;
}
.color-red {
color: red;
}
.color-green {
color: green;
}
.color-yellow {
color: yellow;
}
.color-blue {
color: blue;
}
.color-magenta {
color: magenta;
}
.color-cyan {
color: cyan;
}
.color-white {
color: white;
}
.bold {
font-weight: bold;
}
.underline {
text-decoration: underline;
}