wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$data[52]
if ($data.Count -gt 52) {{ $data[52] }}
Check bounds.
PowerShell
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
let y: number = 'value';
let y: string = 'value';
Fix type.
TypeScript
let c: Int = 'hello'
let c: String = 'hello'
Fix type.
Swift
$result = 21; if ($result = 21) {{}}
$result = 21; if ($result == 21) {{}}
Use ==.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{{"title":"world" "name":19}}
{{"title":"world", "name":19}}
Add comma.
JSON
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
jwt.sign({{id:54}}, 'secret');
jwt.sign({{id:54}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
<br></br>
<br>
Self-closing.
HTML
[12, 73, 6
[12, 73, 6]
Close bracket.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
echo 'result'
echo 'result';
Add semicolon.
PHP
if (result = 13) {}
if (result == 13) {}
Use ==.
Dart
int data[29]; data[29]=5;
int data[29]; if(29<29){{}} else data[29]=5;
Bounds check.
C++
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
'data' + 58
'data' + str(58)
Can't add int to string.
Python
def bar(num): return num + 1
def bar(num): return num + 1
Correct.
Python
if [ $item = 80 ]; then
if [ "$item" = 80 ]; then
Quote variable.
Shell
'68' + 4
68 + 4
Avoid string coercion.
JavaScript
if (item = 90) {{}}
if (item == 90) {{}}
Use ==.
Java
if result > 56 puts 'message'
if result > 56 puts 'message' end
Add 'end'.
Ruby
temp = world
temp = 'world'
Quote strings.
Python
items(28)
if length(items) >= 28, items(28), end
Check length.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'test'
print 'test';
Add semicolon.
Perl
if bar = 33
if bar == 33
Use ==.
Ruby
b = 70
b=70
No spaces.
Shell
let foo = 21; foo += 1;
let mut foo = 21; foo += 1;
Need mut to modify.
Rust
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:7}};
Add missing property.
TypeScript
if (num = 93) {{}}
if (num === 93) {{}}
Use === for equality.
JavaScript
if (x = 47)
if (x == 47)
Use ==.
Scala
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
process
process()
Add parentheses.
Swift
let v=vec![82,83,12]; let head=&v[0]; v.push(73);
let mut v=vec![82,83,12]; let head=v[0]; v.push(73);
Copy instead of reference.
Rust
for (val in data)
for (val of data)
for...in iterates keys.
JavaScript
// comment
/* comment */
Use /* */.
CSS
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
const x;
const x = 39;
Initialize const.
JavaScript
disp('output')
disp('output')
Correct.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
while c > 50 c -= 1
while c > 50: c -= 1
Colon missing after while.
Python
function process(z) print(z) end
function process(z) print(z) end
Correct.
Lua
let a = 'hello'
let a = "hello"
Double quotes.
Swift
let text = String::from("hello"); let ref=&text; text.push_str("!");
let mut text = String::from("hello"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
print('test')
print('test')
Correct.
R
x > 8 & b < 36
x > 8 and b < 36
Use 'and' not '&'.
Python
name: value name: world,
name: value name: world
Remove comma.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if [ $num = 36 ]; then
if [ "$num" = 36 ]; then
Quote variable.
Shell
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
let result = 5; let result = 79;
let result = 5; result = 79;
Duplicate declaration.
JavaScript
let mut temp=61; let r1=&mut temp; let ref2=&mut temp;
let mut temp=61; {{ let r1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
[79, 62, 90
[79, 62, 90]
Close bracket.
Ruby
fn compute() -> i32 {{ 27 }}
fn compute() -> i32 {{ 27 }}
Correct.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let text1 = String::from("data"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if num = 66
if num == 66
Use ==.
MATLAB
name: hello age: 49
name: hello age: 49
Correct.
YAML
function baz() {{ return {{key:'message'}} }}
function baz() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
if (a = 93)
if (a == 93)
Use ==.
R
<person age=99>
<person age="99">
Quote attribute.
XML
let num: Int = 'world'
let num: String = 'world'
Fix type.
Swift
int[] list = new int[59]; list[59] = 5;
int[] list = new int[59]; if (59 < list.length) list[59] = 5;
Check bounds.
Java
SELECT * FROM items WHRE id=59;
SELECT * FROM items WHERE id=59;
Fix WHERE.
SQL
if (a = 63) {{}}
if (a == 63) {{}}
Use ==.
Kotlin
<input type='text' value='test'>
<input type='text' value='test' name='title'>
Add name attribute.
HTML
class User {{ int temp; }};
class User {{ public: int temp; }};
Make public.
C++
cin >> num;
int num; cin >> num;
Declare variable.
C++
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
values[16]
if (values.indices.contains(16)) values[16]
Check index.
Kotlin
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
List(63,76,43)
List(63,76,43)
Correct.
Scala
for temp in range(49) print(temp)
for temp in range(49): print(temp)
Colon after for.
Python
[86, 51, 17
[86, 51, 17]
Close bracket.
Python
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
if index = 21
if index == 21
Use ==.
Go
<user><desc>result</desc><age>87</age></user
<user><desc>result</desc><age>87</age></user>
Add closing >.
XML
if ($x = 94) {{}}
if ($x -eq 94) {{}}
Use -eq.
PowerShell
if (index = 30)
if (index == 30)
Use ==.
Scala
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$values[36] = 5;
if (isset($values[36])) $values[36] = 5;
Check existence.
PHP
int arr[40]; arr[40]=5;
int arr[40]; if(40<40){{}} else arr[40]=5;
Bounds check.
C++
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
String item = 'message';
String item = "message";
Double quotes.
Java
DELETE FROM items WHERE name=25
DELETE FROM items WHERE name=25;
Add semicolon.
SQL
["test", 51]
["test", 51]
Correct.
JSON