Skip to content

Commit f131ca7

Browse files
committed
Disallow str to []int8 casts (#510)
1 parent 1dce512 commit f131ca7

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

doc/lang.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ If a value `s` of type `S` is given where a value `t` of some other type `T` is
437437
* `S` and `T` are ordinal types
438438
* `S` and `T` are pointer types and `sizeof(s^) >= sizeof(t^)` and both `S` and `T` don't contain pointers
439439
* `S` is an interface type and `T` is a type (or a pointer to a type) that was actually converted to `S`
440-
* `S` is `[]int8` or `[]uint8` and `T` is `str`
441-
* `S` is `str` and `T` is `[]int8` or `[]uint8`
440+
* `S` is `[]uint8` and `T` is `str`
441+
* `S` is `str` and `T` is `[]uint8`
442442
* `S` is `[]U`, `T` is `[]V` and `U` can be explicitly converted to `V`
443443

444444
## Declarations

playground/umka.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/umka_expr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,13 +713,13 @@ void doExplicitTypeConv(Compiler *comp, Type *dest, Type **src, Const *constant)
713713
}
714714

715715
// Dynamic array to string
716-
else if ((*src)->kind == TYPE_DYNARRAY && ((*src)->base->kind == TYPE_INT8 || (*src)->base->kind == TYPE_UINT8) && dest->kind == TYPE_STR)
716+
else if ((*src)->kind == TYPE_DYNARRAY && (*src)->base->kind == TYPE_UINT8 && dest->kind == TYPE_STR)
717717
{
718718
doDynArrayToStrConv(comp, dest, src, constant, false);
719719
}
720720

721721
// String to dynamic array
722-
else if ((*src)->kind == TYPE_STR && dest->kind == TYPE_DYNARRAY && (dest->base->kind == TYPE_INT8 || dest->base->kind == TYPE_UINT8))
722+
else if ((*src)->kind == TYPE_STR && dest->kind == TYPE_DYNARRAY && dest->base->kind == TYPE_UINT8)
723723
{
724724
doStrToDynArrayConv(comp, dest, src, constant);
725725
}

src/umka_vm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,7 @@ static FORCE_INLINE void doBuiltinMakefromarr(Fiber *fiber, HeapPages *pages, Er
20722072
}
20732073

20742074

2075-
// fn makefromstr(src: str): []char | []int8 | []uint8
2075+
// fn makefromstr(src: str): []char | []uint8
20762076
static FORCE_INLINE void doBuiltinMakefromstr(Fiber *fiber, HeapPages *pages, Error *error)
20772077
{
20782078
DynArray *dest = (DynArray *)(fiber->top++)->ptrVal;
@@ -2118,7 +2118,7 @@ static FORCE_INLINE void doBuiltinMaketoarr(Fiber *fiber, HeapPages *pages, Erro
21182118
}
21192119

21202120

2121-
// fn maketostr(src: char | []char | []int8 | []uint8): str
2121+
// fn maketostr(src: char | []char | []uint8): str
21222122
static FORCE_INLINE void doBuiltinMaketostr(Fiber *fiber, HeapPages *pages, Error *error)
21232123
{
21242124
char *dest = doGetEmptyStr();

tests/expected.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ Hey Hello
750750
HellHell
751751
HellHell
752752
[72 101 108 108 111 44 32 66 114 97 118 101 32 78 101 119 32 87 111 114 108 100 33]
753-
[72 101 108 108 111 44 32 -48 -76 -48 -72 -48 -78 -48 -67 -47 -117 -48 -71 32 -48 -67 -48 -66 -48 -78 -47 -117 -48 -71 32 -48 -68 -48 -72 -47 -128 33]
753+
[72 101 108 108 111 44 32 208 180 208 184 208 178 208 189 209 139 208 185 32 208 189 208 190 208 178 209 139 208 185 32 208 188 208 184 209 128 33]
754754
Hello, Brave New World!
755755
Hello, дивный новый мир!
756756
['P' 'Q'] "PQ" 2 2

tests/safecast.um

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn test3() {
7373
fn test4() {
7474
s := "Hello,"
7575
a := []uint8(s + " Brave New World!")
76-
b := []int8(s + " дивный новый мир!")
76+
b := []uint8(s + " дивный новый мир!")
7777
printf("%v\n%v\n", a, b)
7878
printf("%s\n%s\n", str(a), str(b))
7979
}

0 commit comments

Comments
 (0)