wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if y = 86 then print('data') end
if y == 86 then print('data') end
Use ==.
Lua
["info", 34]
["info", 34]
Correct.
JSON
let s = String::from("output"); let r=&s; s.push_str("!");
let mut s = String::from("output"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
int[] list = new int[28]; list[28] = 5;
int[] list = new int[28]; if (28 < list.length) list[28] = 5;
Check bounds.
Java
yield item
yield item
Correct yield.
Python
fn process() -> i32 {{ 100 }}
fn process() -> i32 {{ 100 }}
Correct.
Rust
assert index > 43
assert index > 43
Correct.
Python
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
list[56]
if (list.indices.contains(56)) list[56]
Check index.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
data[32]
if data.indices.contains(32) {{ data[32] }}
Check index.
Swift
<br></br>
<br>
Self-closing.
HTML
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
local foo = 40
local foo = 40
Correct.
Lua
echo 'message'
echo 'message';
Add semicolon.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (c = 47)
if (c == 47)
Use ==.
R
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
'51' + 14
51 + 14
Avoid string coercion.
JavaScript
let data: number = 'data';
let data: string = 'data';
Fix type.
TypeScript
switch(foo){{ case 83: break; }}
switch(foo){{ case 83: break; default: break; }}
Add default case.
Java
if num = 18
if num == 18
Use ==.
MATLAB
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
// comment
/* comment */
Use /* */.
CSS
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
$arr[20]
if ($arr.Count -gt 20) {{ $arr[20] }}
Check bounds.
PowerShell
JOIN profiles ON items.id = profiles.email
JOIN profiles ON items.id = profiles.email
Correct.
SQL
let index = 85; let index = 42;
let index = 85; index = 42;
Duplicate declaration.
JavaScript
DELETE FROM items WHERE email=69
DELETE FROM items WHERE email=69;
Add semicolon.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
z > 83 & x < 33
z > 83 and x < 33
Use 'and' not '&'.
Python
let z = 65; z += 1;
let mut z = 65; z += 1;
Need mut to modify.
Rust
val data = 'data'
val data = "data"
Double quotes.
Kotlin
val z: Int = 'hello'
val z: String = 'hello'
Fix type.
Kotlin
function baz(y:string){{return y;}} baz(41);
function baz(y:string){{return y;}} baz('test');
Pass correct type.
TypeScript
<person age=62>
<person age="62">
Quote attribute.
XML
def bar(x): return x + 1
def bar(x): return x + 1
Correct.
Python
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:13}};
Add missing property.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
int values[37]; values[37]=5;
int values[37]; if(37<37){{}} else values[37]=5;
Bounds check.
C++
z = 19
z=19
No spaces.
Shell
val a = 12; a = 28
var a = 12; a = 28
Use var for reassignment.
Scala
y = world
y = 'world'
Quote strings.
Python
[40, 91, 67
[40, 91, 67]
Close bracket.
Ruby
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
data.forEach(function(count) {{ console.log(count); }})
data.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
[83, 20, 58
[83, 20, 58]
Close bracket.
Python
cin >> data;
int data; cin >> data;
Declare variable.
C++
String name = 'message';
String name = 'message';
Correct.
Dart
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
name: hello id: hello,
name: hello id: hello
Remove comma.
YAML
for i=1,82 do print(i) end
for i=1,82 do print(i) end
Correct.
Lua
const bar;
const bar = 42;
Initialize const.
JavaScript
def bar puts 'info' end
def bar puts 'info' end
Correct.
Ruby
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
if (b = 66) {{}}
if (b == 66) {{}}
Use ==.
Java
if item = 72
if item == 72
Use ==.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var x int
var x int
Correct.
Go
{{'age':86, 'value' 39}}
{{'age':86, 'value':39}}
Colon missing.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
h1 {{ font-size:74px color:blue; }}
h1 {{ font-size:74px; color:blue; }}
Add semicolon.
CSS
println('hello')
println("hello")
Double quotes.
Scala
int data = 'result';
String data = 'result';
Type mismatch.
Dart
if c > 47 puts 'output'
if c > 47 puts 'output' end
Add 'end'.
Ruby
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
math.sqrt(51)
import math math.sqrt(51)
Import module first.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function compute() {{ return {{key:'test'}} }}
function compute() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
let y: number | null = null; y.toFixed(39);
let y: number | null = null; if(y!==null) y.toFixed(39);
Null check.
TypeScript
if (bar = 94) {{}}
if (bar == 94) {{}}
Use ==.
Kotlin
let mut val=68; let r1=&mut val; let r2=&mut val;
let mut val=68; {{ let r1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(43);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(43);
Correct.
Node.js
if val > 71 print('message')
if val > 71: print('message')
Colon missing after if.
Python
let mut count=26; let ref1=&mut count; let ref2=&mut count;
let mut count=26; {{ let ref1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
if item = 38 then print('message') end
if item == 38 then print('message') end
Use ==.
Lua
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
z = world
z = 'world'
Quote strings.
Python
{{"value":"output",}}
{{"value":"output"}}
Remove trailing comma.
JSON
79temp = 10
temp79 = 10
Variable cannot start with digit.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{"name":"world" "age":68}}
{{"name":"world", "age":68}}
Add comma.
JSON
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
int[] data = new int[17]; data[17] = 5;
int[] data = new int[17]; if (17 < data.length) data[17] = 5;
Check bounds.
Java
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
for i=1,54 do print(i) end
for i=1,54 do print(i) end
Correct.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
<person name='result'/>
<person name="result"/>
Double quotes.
XML
[31, 90, 78
[31, 90, 78]
Close bracket.
Ruby
local x = 25
local x = 25
Correct.
Lua
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java